I've been using these forums as resource since I'm new to PHP/MySQL, and I've found a ton of help here. I've built a site for myself, and so far, everything works exactly like I want it to, except for a rather simple thing.
I have an administrative section where I can add new news items, t-shirts and workshirts to the db. Those pages work perfectly. However, the pages I've tried creating to edit the records already in the db don't work. I've tried countless versions of code, many culled from these forums, and none has been successful.
To use one section as an example, I have a page (display_tshirts.php) that displays all the t-shirt records on a page. Each displayed record has a link that passes the id of the record to the edit_tshirt.php page, which populates a form with the fields from the record. This part works fine. When I make a change to the information in the form and submit it, all it does is reload the page with the same information still populated, including the change, however, it does not actually update the db.
It's frustrating because I've been trying to find the solution to this rather simple issue for about a week now, and even though this seems to be a common problem posted here, none of the solutions I've found here work for me.
By the way, the UPDATE code I'm trying this time was taken from this thread: http://www.phpbuilder.com/board/showthread.php?threadid=10268595&highlight=update
I did try the suggestion in above thread about changing "$sid = $GET['s_id'];" to "$sid = $POST['s_id'];" and changing the form action to "edit_tshirt.php?s_id=<?php echo $_GET['s_id'];" but when I did that, the id did not get passed from previous page link and the form was empty.
Here's the code for my edit_tshirt.php page, can anyone tell me what I've screwed up? Many thanks.
..........................
<?php
//connect to the db
require_once('/connect.php');
//set page title
$page_title = 'admin area : edit t-shirt';
//header include
include_once('/propaganda/includes/header1.htm');
//grab the variable passed from the display page
$sid = $_GET['s_id'];
//handle the form
if ($_POST['submit']) {
$sn = $_POST['s_name'];
$sc = $_POST['s_color'];
$ss = $_POST['s_size'];
$sd = $_POST['s_desc'];
$sp = $_POST['s_price'];
$si = $_POST['s_image'];
if ($sid) {
$query = "UPDATE shirts SET s_name='$sn', s_color='$sc', s_size='$ss', s_desc='$sd', s_price='$sp', s_image='$si' WHERE s_id=$sid" OR die ('Could not run query!');
$result = @mysql_query ($query);
}
}
if ($sid) {
$query = "SELECT * FROM shirts WHERE s_id=$sid";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$sn = $row['s_name'];
$sc = $row['s_color'];
$ss = $row['s_size'];
$sd = $row['s_desc'];
$sp = $row['s_price'];
$si = $row['s_image'];
}
mysql_free_result($result);
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="s_id" value="<?php echo $sid; ?>">
<p class="headline">
edit a t-shirt</p>
<!-- nested form table -->
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td valign="top">
<font class="digiToo">
t-shirt name:</font></td>
<td valign="top">
<input type="text" name="s_name" size="15" maxlength="100" value="<?php echo $sn; ?>" /></td>
</tr>
<!-- shirt color -->
<tr>
<td valign="top">
<font class="digiToo">
t-shirt color:</font></td>
<td valign="top">
<input type="text" name="s_color" size="10" maxlength="10" value="<?php echo $sc; ?>" /></td>
</tr>
<!-- shirt size -->
<tr>
<td valign="top">
<font class="digiToo">
t-shirt size:</font></td>
<td valign="top">
<input type="text" name="s_size" size="8" maxlength="8" value="<?php echo $ss; ?>" /></td>
</tr>
<!-- shirt description -->
<tr>
<td valign="top">
<font class="digiToo">
t-shirt description:</font></td>
<td valign="top">
<textarea name="s_desc" cols="36" rows="6"><?php echo $sd; ?></textarea></td>
</tr>
<!-- shirt price -->
<tr>
<td valign="top">
<font class="digiToo">
t-shirt price:</font></td>
<td valign="top">
<input type="text" name="s_price" size="5" maxlength="5" value="<?php echo $sp; ?>" /></td>
</tr>
<!-- shirt image -->
<tr>
<td valign="top">
<font class="digiToo">
t-shirt image:</font></td>
<td valign="top">
<input type="text" name="s_image" size="15" maxlength="30" value="<?php echo $si; ?>"/></td>
</tr>
<!-- submit -->
<tr>
<td valign="top">
</td>
<td valign="top">
<input type="submit" name="submit" value="submit" /></form></td>
</tr>
</table></form></td>
<!-- spacer col -->
<td valign="top" width="20">
<img src="/images/spacer.gif" border="0" width="20" height="10" alt="" /></td>
<!-- spacer col -->
<td valign="top" width="20">
<img src="/images/spacer.gif" border="0" width="20" height="10" alt="" /></td>
<?php
include_once('/propaganda/includes/footer1.htm');
?>