PHP/MYSQL question please help!
Posted: Sat Mar 06, 2010 11:04 pm
The goal of this project is to create 3 php scripts one to add, one to update and one to delete information from a mysql database. I have the add and the delete done but I am having trouble with the update. When you select the record to update the php script is suppose to populate the fields back into a form that can be submited to update the mysql database. The fields end up being blank on the update page and also the update script is not working. Any help would be greatly appriciated! The edit php script works fine so I dont believe that is where the error is.
edit.php
editform.php
editdata.php
edit.php
Code: Select all
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table>
<tr>
<td align="center">EDIT DATA</td>
</tr>
<tr>
<td>
<table border="1">
<?
include "connect.php";
$order = "SELECT * FROM product";
$result = mysql_query($order);
while ($row=mysql_fetch_array($result)){
echo ("<tr><td>$row[productnumber]</td>");
echo ("<td>$row[name]</td>");
echo ("<td>$row[description]</td>");
echo ("<td>$row[price]</td>");
echo ("<td>$row[weight]</td>");
echo ("<td>$row[qoh]</td>");
echo ("<td><a href=\"editform.php?
id=$row[productnumber]\">Edit</a></td></tr>");
}
?>
</table>
</td>
</tr>
</table>
</body>
</html>
Code: Select all
<html>
<head>
<title>Form Edit Data</title>
</head>
<body>
Edit Product Data
<?
include "connect.php";
$order = "SELECT * FROM product where productnumber ='$id'";
$result = mysql_query($order);
$row = mysql_fetch_array($result);
?>
<form method="post" action="editdata.php">
<p>
<input type="hidden" name="id" value="<? echo "$row[productnumber]"?>">
Name: <input type="text" name="name" size="20" value="<? echo "$row[name]"?>">
</p>
<p>Description:
<input type="text" name="description" size="40" value="<? echo ("$row[description]")?>">
</p>
<p>
Weight: <input type="text" name="weight" size="5" value="<? echo "$row[weight]"?>">
</p>
<p>Price:
<input type="text" name="price" size="10" value="<? echo "$row[price]"?>">
</p>
<p>Quantity On Hand:
<input type="text" name="description" size="4" value="<? echo "$row[qoh]"?>">
</p>
<p>
<input type="submit" name="submit value" value="Edit">
</p>
</form>
</body>
</html>
Code: Select all
<?
include "connect.php";
$order = "UPDATE product SET name='$name', description='$description', price='$price', weight ='$weight', qoh= $qoh' WHERE productnumber='$id'";
mysql_query($order);
header("location:edit.php");
?>