Jump to content


This topic is now archived and is closed to further replies.


need help Modifying data stored in MySQL tables with PHP

Recommended Posts

Moving right along. Theses forums are helping me LEARN in INTREPRUT alot more than my 700 page php/mySQL book.

I have a script that i've written. So far it selects the information form a row in a table and displays it in a conventinol html table.

I want  to have forms below my table to edit the stored data.
The only stored data I am looking to modify for now is item Name, Price and description as I have not even thought of a way to approach the avilibilty and catagories. Ill tackel that later.

the comments I've made in the script show what I have so far and where I left off:
Thanks in advance if anyone can help:


/// Store Passed Data as $id
$id = $_GET['id'];
/// Select data from  mySQL table
$qry = "SELECT itemName,itemCat,itemSub,itemId,itemPrice,itemDesc,itemSmall FROM `products` WHERE `itemId`=\"$id\"";
$result = mysql_query($qry) or die(mysql_error());

/// edit page header
echo "Listed below is the stored data for the item #$id <br /> Use the fields below the item table to modify the information.";
echo "<br /> ";
echo "<br />";
echo "<br />";

/// Display item data loop
while($row = mysql_fetch_array($result))

echo "<table border=\"1\"><tr><td>".$row['itemName']."<td>".$row['itemId']."</td></td></tr>";
echo "<tr><td><img src=\"".$row['itemSmall']."\" /></td><td valign=top width=150>Description:<br />".$row['itemDesc']."</td>";
echo "</tr><tr><td>Price: $".$row['itemPrice']."</td><td>Avilibility: </td></tr>";
echo "<tr><td width=150>Catagory: ".$row['itemCat']."</td><td width=150>Sub-Catagory:".$row['itemSub']."</td></tr>";
echo "</table>";
echo "<br / ";

/// Display fields for data modification.... This is where Im stumped. Help :o
die("<html><body><form action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">


Share this post

Link to post
Share on other sites
you'd have to use the UPDATE query.. you'll have to go UPDATE (which table) and SET (row) WHERE (something=something).. heres an example you should understand it after this.. this is to a password change in a membership thing

[code]mysql_query("UPDATE users SET password='$db_password' 
                WHERE email_address='$email_address'");[/code]
here the table in the db is found.. the row that needs to be changed depending on the email address given

hope that helps

Share this post

Link to post
Share on other sites
assuming that "itemId" is always going to be an integer you might wanna type cast it for security (ebil sql injection!)

[code]$id = $_GET['id'];[/code]

would be safer as

[code]$id = (int)$_GET['id'];[/code]

always nicer to be paranoid ;D

Share this post

Link to post
Share on other sites


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.