Hi guys,
I have this script that's supposed to update existing records in mysql, but for some reason it doesnt. It's weird because I can add and delete records, but not modify. Can anyone look at the script and tell me what I'm doing wrong? Thanks!
PHP script
--------------------------------------------------------------------------------------
<?
// START PHP CODES. THIS PART MUST ON THE TOP OF THIS PAGE.
// Connect database.
include 'config.php';
include 'opendb.php';
// ***** This part will process when you Click on "Submit" button *****
// Check, if you clicked "Submit" button
if($Submit){
// Get parameters from form.
$id=$_POST['id'];
$establishment=$_POST['establishment'];
$code=$_POST['code'];
$zipcode=$_POST['zipcode'];
$expiry_date=$_POST['expiry_date'];
// Do update statement.
mysql_query("UPDATE upload2 SET establishment='$establishment', code='$code', zipcode='$zipcode' , expiry_date='$expiry_date' where id='$id'");
// Close database connection.
mysql_close();
// Re-direct this page to select.php.
header("location:coupons_admin.php");
}
// ************* End update part *************
?><?
// *** Select data to show on text fields in form. ***
// Get id parameter (GET method) from select.php
$id=$_GET['id'];
// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("select * from upload2 where id='$id'");
// Split records in $result by table rows and put them in $row.
$row=mysql_fetch_assoc($result);
// Close database connection.
mysql_close();
?>
HTML form
--------------------------------------------------------------------------------------
<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">
<table width="396" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="142" class="style119">Establishment:</td>
<td width="247"><input name="establishment" type="text" id="establishment" value="<? echo $row['establishment']; ?>"></td>
</tr>
<tr>
<td class="style119">Coupon Code: </td>
<td><input name="code" type="text" id="code" value="<? echo $row['code']; ?>"></td>
</tr>
<tr>
<td class="style119">Zip Code: </td>
<td><input name="zipcode" type="text" id="zipcode" value="<? echo $row['zipcode']; ?>"></td>
</tr>
<tr>
<td class="style119">Expiry Date: </td>
<td><input name="expiry_date" type="text" id="expiry_date" value="<? echo $row['expiry_date']; ?>"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="Submit" type="submit" class="box" id="submit" value="Submit">
</div></td>
</tr>
</table>
</form>
I have this script that's supposed to update existing records in mysql, but for some reason it doesnt. It's weird because I can add and delete records, but not modify. Can anyone look at the script and tell me what I'm doing wrong? Thanks!
PHP script
--------------------------------------------------------------------------------------
<?
// START PHP CODES. THIS PART MUST ON THE TOP OF THIS PAGE.
// Connect database.
include 'config.php';
include 'opendb.php';
// ***** This part will process when you Click on "Submit" button *****
// Check, if you clicked "Submit" button
if($Submit){
// Get parameters from form.
$id=$_POST['id'];
$establishment=$_POST['establishment'];
$code=$_POST['code'];
$zipcode=$_POST['zipcode'];
$expiry_date=$_POST['expiry_date'];
// Do update statement.
mysql_query("UPDATE upload2 SET establishment='$establishment', code='$code', zipcode='$zipcode' , expiry_date='$expiry_date' where id='$id'");
// Close database connection.
mysql_close();
// Re-direct this page to select.php.
header("location:coupons_admin.php");
}
// ************* End update part *************
?><?
// *** Select data to show on text fields in form. ***
// Get id parameter (GET method) from select.php
$id=$_GET['id'];
// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("select * from upload2 where id='$id'");
// Split records in $result by table rows and put them in $row.
$row=mysql_fetch_assoc($result);
// Close database connection.
mysql_close();
?>
HTML form
--------------------------------------------------------------------------------------
<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">
<table width="396" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="142" class="style119">Establishment:</td>
<td width="247"><input name="establishment" type="text" id="establishment" value="<? echo $row['establishment']; ?>"></td>
</tr>
<tr>
<td class="style119">Coupon Code: </td>
<td><input name="code" type="text" id="code" value="<? echo $row['code']; ?>"></td>
</tr>
<tr>
<td class="style119">Zip Code: </td>
<td><input name="zipcode" type="text" id="zipcode" value="<? echo $row['zipcode']; ?>"></td>
</tr>
<tr>
<td class="style119">Expiry Date: </td>
<td><input name="expiry_date" type="text" id="expiry_date" value="<? echo $row['expiry_date']; ?>"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="Submit" type="submit" class="box" id="submit" value="Submit">
</div></td>
</tr>
</table>
</form>
Comment