PHP mySQL Navigation

August 28, 2009 at 09:59:00
Specs: Macintosh
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.



See More: PHP mySQL Navigation

Report •

September 1, 2009 at 14:00:18

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



   $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" .
      } else {
         $page = "resource failed";

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

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

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.

Report •
Related Solutions

Ask Question