Jump to content


need help Modifying data stored in MySQL tables with PHP

  • Please log in to reply
2 replies to this topic

#1 tet3828

  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts
  • Locationfort myers, FL

Posted 30 October 2006 - 07:56 PM

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\">


[ Enter Your Signature Here ]
Always take caution when using other peoples work.

#2 jwk811

  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 30 October 2006 - 08:10 PM

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

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

hope that helps

#3 genericnumber1

  • Members
  • PipPipPip
  • Advanced Member
  • 1,858 posts

Posted 30 October 2006 - 08:53 PM

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

$id = $_GET['id'];

would be safer as

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

always nicer to be paranoid ;D

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users