Jump to content

Edit Rows in database?


wooowooo

Recommended Posts

Hi

 

Anyone know where the error is in my code? I cannt find it :(

 

The solution only displays " - Edit " it doesnt show the name and when you click it the information isnt displayed to update the record

 

Thanks

 


<?php

//connect to database

//If cmd has not been initialized
if(!isset($cmd)) 
{
   //display the whole menu
   $result = mysql_query("select * from week10 order by name ASC"); 
   
   //run the while loop that grabs all the news scripts
   while($r=mysql_fetch_array($result)) 
   { 
      //grab the name and the ID of the menu item
      $name=$r["name"];//take out the name
      $menuID=$r["menuID"];//take out the id
     
 //make the title a link
      echo "<a href='edit.php?cmd=edit&name=$name'>$title - Edit</a>";
      echo "<br>";
    }
}
?>

<?php
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
   if (!isset($_POST["submit"]))
   {
      $menuID = $_GET["menuID"];
      $sql = "SELECT * FROM week10 WHERE name=$name";
      $result = mysql_query($sql);        
      $myrow = mysql_fetch_array($result);
      ?>
  
      <form action="wk10ex2.php" method="post">
      <input type=hidden name="id" value="<?php echo $myrow["menuID"] ?>">
   
      Name:<INPUT TYPE="TEXT" NAME="name" VALUE="<?php echo $myrow["name"] ?>" SIZE=30><br>
      Description:<TEXTAREA NAME="description" VALUE="<? echo $myrow["description"] ?>"</TEXTAREA><br>
      Price:<INPUT TYPE="TEXT" NAME="price" VALUE="<?php echo $myrow["price"] ?>" SIZE=30><br>
   
      <input type="hidden" name="cmd" value="edit">
   
      <input type="submit" name="submit" value="submit">
   
      </form>
   
   <?php } ?>
   
<?php
   if ($_POST["$submit"])
   {
      $name = $_POST["name"];
      $description = $_POST["description"];
      $price = $_POST["price"];

      $sql = "UPDATE week10 SET name='$name',description='$description',price='$price' WHERE menuID=$menuID";

      $result = mysql_query($sql);
      echo "Thank you! Information updated.";
   }
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.