Computing.Net > Forums > Web Development > PHP mySQL Navigation

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

PHP mySQL Navigation

Reply to Message Icon

Name: JoeV
Date: August 28, 2009 at 09:59:00 Pacific
OS: Macintosh
Subcategory: PHP
Comment:

I'm a newbie on these things so I might be asking for
something that can't be done.

I have a navigation bar (#navbar) with links that when
each of the links is clicked, the click will update the
content in the (#maincontent) div. This is done with
PHP includes and works well. The include page has
the content in the file.

What I would like to do is make the content on the
include page dynamic, so that the user could update
the mySQL database and in turn update the content
for that page. I'm using Dreamweaver and I can add
dynamic content to the include page via PHP but the
dynamic content does not display once the include is
called for. The include page does show the dynamic
content when viewed by itself. The Recordset is in the
include page.

Any help would be appreciated.

Thanks,

Joe



Sponsored Link
Ads by Google

Response Number 1
Name: shutat
Date: September 1, 2009 at 14:00:18 Pacific
Reply:

Hi,

I'm not sure if it's what you're after or how close it is to what you already have, but you *might* try something similar to

<?php

   unset($page);

   $link = mysql_connect("localhost", "user", "passw");
   if(!$link) { die(mysql_error()); }
   if(!mysql_select_db("dbname", $link)) { die(mysql_error()); }

   mysql_query("create table if not exists tbl_test(
          id int(6) auto_increment,
          content text(8192),
          primary key(id)
        )type=myisam;") or die(mysql_error());

   if(mysql_num_rows(mysql_query("select content from tbl_test where id=1 limit 1;")) == 0) {
      mysql_query("insert into tbl_test values('null', 'some initial content');") or die(mysql_error());
   }

   if(isset($_POST["cmd"]) && $_POST["cmd"] === "Update") {

      $res = mysql_query("update tbl_test set content='" 
             . $_POST["content"] . "' where id=" . $_POST["sel_id"] . " limit 1;") or die(mysql_error());

      header("location: " . $_SERVER["PHP_SELF"] . "?p=1");

   } else if(isset($_GET["p"]) && $_GET["p"] === "1") {

      $res = mysql_query("select * from tbl_test where id=1 limit 1;") or die(mysql_error());
      if(is_resource($res)) {
         $data = mysql_fetch_row($res);
         $page = "<strong>current data</strong>: " . $data[1] . 
               "<form action='" . $_SERVER["PHP_SELF"] . "' method='post'>\n" .
               "<input name='sel_id' type='hidden' value='" . $data[0] . "'>\n" .
               "<textarea name='content' rows='10' cols='60'></textarea>\n" .
               "<input name='cmd' value='Update' type='submit'>\n" .
               "</form>";
      } else {
         $page = "resource failed";
      }
   } 

   mysql_close($link);
?>
<table cellpadding="10">
<tr>
<td width="20%" valign="top">
<a href="<?php echo $_SERVER["PHP_SELF"];?>?p=1">navbar 1</a>

</td>
<td width="80% valign="top">
<?php echo $page; ?>
</td>
</tr>
</table>

There is NO error checking of any kind. You likely wouldn't need most of the code to create and insert data either... I did that to crudely test it.

Hope that helps or at least gives you an idea to try.


0
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: PHP mySQL Navigation

PHP/MySQL/Apache Info www.computing.net/answers/webdevel/phpmysqlapache-info/1834.html

How do I setup PHP & MySQL on XP www.computing.net/answers/webdevel/how-do-i-setup-php-amp-mysql-on-xp/122.html

PHP, MySQL, phpMyAdmin www.computing.net/answers/webdevel/php-mysql-phpmyadmin/1590.html