/    Sign up×
Community /Pin to ProfileBookmark

need help creating an update section

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

to post a comment
PHP

11 Comments(s)

Copy linkTweet thisAlerts:
@scragarDec 01.2004 — if you post a link to the form I could make this code more direct...

when linking to updateproducts.php should specifie the item id in the url like below.

<a href="updateproducts.php?Item_ID=[i]ItemID[/i]">link</a>

[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]


For this I asumed that where you had spaces in the item names it should be an underscore(_) and just used the form names that I myself would naturaly use AND that you have autoslashes enabled.

tell me the form's URL and I can help you out some more.
Copy linkTweet thisAlerts:
@mikewootenauthorDec 01.2004 — i have the ID working now, and it goes to an edit.php page but when the form shows up on the edit.php page, the values or information does not show up in the form from the showprod4.php page, how do you get the information inside of the form on the edit.php page?

here is the code that i have for each of the pages.

here the code for showprod4.php:

[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]



this is the code that i have for the edit2.php page
[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]
Copy linkTweet thisAlerts:
@scragarDec 01.2004 — do you have a link so I can see what you mean, it might just be that I'm bored and havn't realy looked at the question but I don't quite get point of your question...
Copy linkTweet thisAlerts:
@mikewootenauthorDec 01.2004 — here's a link to the page i'm working on

[URL=http://www.wootenmedia.com/rmg/test/showprod4.php]http://www.wootenmedia.com/rmg/test/showprod4.php[/URL]
Copy linkTweet thisAlerts:
@scragarDec 01.2004 — I can't see a problem, is this all the code you have in the page or is it a different peice that writes out the list at the top of the page?

like I said though, this may just be because I'm bored...
Copy linkTweet thisAlerts:
@mikewootenauthorDec 01.2004 — the code that i have posed above is all that i have on each of the pages, the first piece of code os from showprod4.php and the other code is from edit2.php

how do you get information into the form from the showprod4.php page?

thanks
Copy linkTweet thisAlerts:
@scragarDec 01.2004 — try echoing all the sites content, I think this may be the cause of the extra infop at the top of the form.

[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]
Copy linkTweet thisAlerts:
@mikewootenauthorDec 01.2004 — i was just doing some troubleshooting and the reason for the extra info at the top is from the foreach statement code that i have.

besides that, how would i get information into the form?

thanks
Copy linkTweet thisAlerts:
@scragarDec 02.2004 — are you sure your reading the correct info from the database inside the form elements?

the Product name should be entered in your database as the txtprodItems...
Copy linkTweet thisAlerts:
@mikewootenauthorDec 02.2004 — i have this code on the showprod4.php page, where could i add addslashes() and stripslashes()?

could someone help me out with this?

thanks

here's the 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]
Copy linkTweet thisAlerts:
@scragarDec 03.2004 — use addslashes when writing to the databse(for strings) and stripslashes when writing the HTML.
×

Success!

Help @mikewooten spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...