1,105,556 Community Members

lease help.Cannot update sql.

Member Avatar
Mariel Pineda
Light Poster
36 posts since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]

When I press the save button it wont update the row if i make some changes. whats wrong with my code can you please help mee.

What is lacking or what do i need to put . Thanks for who will answer I will really appreciate it.

$code =$_GET['Code'];
$result = mysql_query("SELECT * FROM books WHERE Code = '$code'");

$row = mysql_fetch_array($result);
if (!$result)
die("Error: Data not found..");
$code =$row['Code'];
$Title=$row['Title'] ;
$Price= $row['Price'] ;
$Stock=$row['Stock'] ;

$title_save = $_GET['title'];
$price_save = $_GET['price'];
$stock_save =$_GET['stock'];

mysql_query("UPDATE books SET Title ='$title_save', Price ='$price_save',
     Stock='$stock_save'  WHERE Code= '$code'")
            or die(mysql_error()); 
echo "Saved!";

header("Location: home_admin.php");         


<form method="get">
<td><input type="text" name="title" value="<?php echo $Title ?>"/></td>
<td><input type="text" name="price" value="<?php echo $Price ?>"/></td>
<td><input type="text" name="stock" value="<?php echo $Stock ?>"/></td>

    <td><input type="submit" name="editsave" value="save" /></td>



Member Avatar
Posting Virtuoso
1,580 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 220 [?]
Skill Endorsements: 21 [?]

I suggest you echo the query to see whether it is what you are expecting. Modifiy the part where you construct the query like this:

// put the query in a variable
$q = "UPDATE books SET Title ='$title_save', Price ='$price_save', Stock='$stock_save' WHERE Code= '$code'";

// submit query using the variable
mysql_query($q) or die(mysql_error(); 

// add this to display the query

Now you will be able to see if the query gets constructed OK and you can copy it to phpmyadmin or mysql client and test it.

Two other notes:

  1. your form has no </form> tag. It should be after </table> tag.
  2. your form is missing an action attribute (I think it is required)
This article has been dead for over three months: Start a new discussion instead
Start New Discussion
Tags Related to this Article