i am working on an administration section. i need help creating an edit/update page where i click the update link on a showproducts.php page, and that link goes to an updateproducts.php page where i can fill out a form on that updateproducts.php page then when i click on the submit button, it updates that product. The information that i would like to update is the category ID, Item ID, Product Item, Item Name, Item Image, Item Description and Item Price.
so far all that i have is just the form, i need help creating the php code for this to work.
is there anyone that can help me out with this, much help would be appreciated.
thanks
[code=php]
<?
if(isset($_POST['ItemID'])){
$sql = "UPDATE tbl SET category_ID=";
$sql .= $_POST['CatID'];
$sql .= ", Product_Item='";
$sql .= $_POST['PItem'];
$sql .= "', Item_Name='";
$sql .= $_POST['IName'];
$sql .= "', Item_Image='";
$sql .= $_POST['I_Img'];
$sql .= "', Item_Description='";
$sql .= $_POST['Idesc'];
$sql .= "', Item_Price=";
$sql .= $_POST['IPrice'];
$sql .= " WHERE Item_ID=";
$sql .= $_POST['ItemID'];
if(mysql_query($sql)){
echo "Your changes were sucessful.";
}else{
echo "SQL identified an error, PHP may have autoslashes disabled or the information may not be valid.";
};
}else{
?>
<!--your form would go here.-->
<?
};
?>[/code]
[code=php]
<?
require_once('book_sc_fns.php');
do_html_header('Administration');
$dbname = "mwooten1_rmgiusa";
$tblname = "items";
$linkid = mysql_connect("localhost", "username", "password") or die("Couldn't connect.");
$db = mysql_select_db($dbname, $linkid) or die("Couldn't select database.");
mysql_query ("SELECT * FROM $tblname");
echo "$select<br>";
$host ="localhost";
$dbuser="username";
$dbpass="password";
$database="mwooten1_rmgiusa";
mysql_connect($host,$dbuser,$dbpass);
mysql_select_db($database) or die ("Unable to select database");
$query="SELECT * FROM $tblname ORDER BY itemId ASC";
$num=mysql_num_rows($result);
$result = mysql_query($query, $linkid);
include("include_code5.php");
echo "<table border='1' bordercolor='#000000' cellpadding='0' cellspacing='0' width='100%'>";
echo "<tr>";
echo "<td width='5%'><strong><center>cat id</center></strong></td>";
echo "<td width='6%'><strong><center>item id</center></strong></td>";
echo "<td width='10%'><strong><center>product item</center></strong></td>";
echo "<td width='10%'><strong><center>item name</center></strong></td>";
echo "<td width='20%'><strong><center>item image</center></strong></td>";
echo "<td width='30%'><strong><center>item desc</center></strong></td>";
echo "<td width='14%'><strong><center>item price</center></strong></td>";
echo "<td width='5%'><strong><center>Delete</td>";
echo "<td width='5%'><strong><center>Update</td>";
echo "</tr>";
while($query_data = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td>$query_data[0]</td>";
echo "<td>$query_data[1]</td>";
echo "<td>$query_data[2]</td>";
echo "<td>$query_data[3]</td>";
echo "<td><img src='../p_imgs/$query_data[4]'></td>";
echo "<td>$query_data[5]</td>";
echo "<td>$query_data[6]</td>";
echo "<td>";
?>
deleterow
<?
echo "</td>";
echo "<td>";
echo('<table border="1"><tr><td><a href="edit2.php?id='.$query_data[1].'">edit'.$row['catid'].'</a></td><td>'.$row['itemName'].'</td><td>'.$row['itemDesc'].'</td><td>'.$row['temPrice'].'</td><td>'.$row['ItemImage'].'</td></tr></table>');
echo "</td>";
echo "</tr>";
}
echo "</table>";
do_html_footer();
?>
[/code]
[code=php]
<?
$tblname = "items";
$host="localhost";
$dbuser="username";
$dbpass="password";
$database="mwooten1_rmgiusa";
mysql_connect($host,$dbuser,$dbpass);
mysql_select_db($database) or die ("Unable to select database");
$txtCatID=(isset($_GET['id']) ? intval($_GET['id']) : "");
if ($txtCatID) {
$query="SELECT * FROM $tblname WHERE catid=$txtCatID";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
?>
<form action="edit.php" method="post">
Category ID: <input type="text" name="catid" value="<? echo $row['txtCatID']; ?>"><br />
Product Item: <input type="text" name="prodItems" value="<? echo $row['txtprodItems']; ?>"><br />
Item Name: <input type="text" name="itemName" value="<? echo $row['txtItemName']; ?>"> <br />
Item Description: <input type="text" name="itemDesc" value="<? echo $row['txtitemDesc']; ?>"><br />
Item Price: <input type="text" name="itemPrice" value="<? echo $row['txtitemPrice']; ?>"><br />
Item Image: <input type="text" name="ItemImage" value="<? echo $row['txtItemImage']; ?>"><br />
<input type="submit" name="submit" value="submit"><input type="reset" />
</form>
<?
}
?>
[/code]
[code=php]<?
$tblname = "items";
$host="localhost";
$dbuser="username";
$dbpass="password";
$database="mwooten1_rmgiusa";
mysql_connect($host,$dbuser,$dbpass);
mysql_select_db($database) or die ("Unable to select database");
$txtCatID=(isset($_GET['id']) ? intval($_GET['id']) : "");
if ($txtCatID) {
$query="SELECT * FROM $tblname WHERE catid=$txtCatID";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
echo "<form action="edit.php" method="post">";
echo "Category ID: <input type="text" name="catid" value="".$row['txtCatID'].""><br />";
echo "Product Item: <input type="text" name="prodItems" value="".$row['txtprodItems'].""><br />";
echo "Item Name: <input type="text" name="itemName" value="".$row['txtItemName'].""> <br />";
echo "Item Description: <input type="text" name="itemDesc" value="".$row['txtitemDesc'].""><br />";
echo "Item Price: <input type="text" name="itemPrice" value="".$row['txtitemPrice'].""><br />";
echo "Item Image: <input type="text" name="ItemImage" value="".$row['txtItemImage'].""><br />";
echo "<input type="submit" name="submit" value="submit"><input type="reset" />";
echo "</form>";
};
?>
[/code]
[code=php]
<?
require_once('book_sc_fns.php');
session_start();
do_html_header('Administration');
$dbname = "mwooten1_rmgiusa";
$tblname = "items";
$linkid = mysql_connect("localhost", "username", "password") or die("Couldn't connect.");
$db = mysql_select_db($dbname, $linkid) or die("Couldn't select database.");
mysql_query ("SELECT * FROM $tblname");
echo "$select<br>";
$host ="localhost";
$dbuser="username";
$dbpass="password";
$database="mwooten1_rmgiusa";
mysql_connect($host,$dbuser,$dbpass);
mysql_select_db($database) or die ("Unable to select database");
$query="SELECT * FROM $tblname ORDER BY itemId ASC";
$num=mysql_num_rows($result);
$result = mysql_query($query, $linkid);
include("include_code5.php");
echo "<table border='1' bordercolor='#000000' cellpadding='0' cellspacing='0' width='100%'>";
echo "<tr>";
echo "<td width='5%'><strong><center>cat id</center></strong></td>";
echo "<td width='6%'><strong><center>item id</center></strong></td>";
echo "<td width='10%'><strong><center>product item</center></strong></td>";
echo "<td width='10%'><strong><center>item name</center></strong></td>";
echo "<td width='20%'><strong><center>item image</center></strong></td>";
echo "<td width='30%'><strong><center>item desc</center></strong></td>";
echo "<td width='14%'><strong><center>item price</center></strong></td>";
echo "<td width='5%'><strong><center>Delete</td>";
echo "<td width='5%'><strong><center>Update</td>";
echo "</tr>";
while($query_data = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td>$query_data[0]</td>";
echo "<td>$query_data[1]</td>";
echo "<td>$query_data[2]</td>";
echo "<td>$query_data[3]</td>";
echo "<td><img src='../p_imgs/$query_data[4]'></td>";
echo "<td>$query_data[5]</td>";
echo "<td>$query_data[6]</td>";
echo "<td>";
?>
deleterow
<?
echo "</td>";
echo "<td>";
echo('<table border="1"><tr><td><a href="edit2.php?id='.$query_data[1].'">edit'.$row['catid'].'</a></td><td>'.$row['itemName'].'</td><td>'.$row['itemDesc'].'</td><td>'.$row['temPrice'].'</td><td>'.$row['ItemImage'].'</td></tr></table>');
echo "</td>";
echo "</tr>";
}
echo "</table>";
do_html_footer();
?>
[/code]
0.1.9 — BETA 5.5