Modifying Mysql DB
Posted: Mon Jan 12, 2004 6:47 pm
I used PHPMaker to create a table to search for data and modify. The search function is working, but I cannot modify the table. When I attempt to modify, it appears to complete, but then I refresh the page nad the original data is still there.
There are only 2 fields in the DB.
Files are all local. Below is the code from my edit file.
TIA
There are only 2 fields in the DB.
Files are all local. Below is the code from my edit file.
TIA
Code: Select all
<?php session_start(); ?>
<?php if (@$HTTP_SESSION_VARSї"serial_status"] <> "login") header("Location: login.php") ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php include ("db.php") ?>
<?php include ("phpmkrfn.php") ?>
<?php
ob_start();
$key = @$HTTP_GET_VARSї"key"];
if (empty($key)) {
$key = @$HTTP_POST_VARSї"key"];
}
if (empty($key)) {
header("Location: seriallist.php");
}
// get action
$a = @$HTTP_POST_VARSї"a"];
if (empty($a)) {
$a = "I"; //display with input box
}
// get fields from form
$x_serial = @$HTTP_POST_VARSї"x_serial"];
$x_used = @$HTTP_POST_VARSї"x_used"];
// open connection to the database
$conn = mysql_connect(HOST, USER, PASS);
mysql_select_db(DB);
switch ($a)
{
case "I": // get a record to display
$tkey = "'" . $key . "'";
$strsql = "SELECT * FROM `serial` WHERE `used`=" . $tkey;
$rs = mysql_query($strsql) or die(mysql_error());
if (!($row = mysql_fetch_array($rs))) {
ob_end_clean();
header("Location: seriallist.php");
}
// get the field contents
$x_serial = @$rowї"serial"];
$x_used = @$rowї"used"];
mysql_free_result($rs);
break;
case "U": // update
$tkey = "'" . $key . "'";
// get the form values
$x_serial = @$HTTP_POST_VARSї"x_serial"];
$x_used = @$HTTP_POST_VARSї"x_used"];
// add the values into an array
// serial
$theValue = (!get_magic_quotes_gpc()) ? addslashes($x_serial) : $x_serial;
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$fieldListї"`serial`"] = $theValue;
// used
$theValue = (!get_magic_quotes_gpc()) ? addslashes($x_used) : $x_used;
$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
$fieldListї"`used`"] = $theValue;
// update
$updateSQL = "UPDATE `serial` SET ";
foreach ($fieldList as $key=>$temp) {
$updateSQL .= "$key = $temp, ";
}
if (substr($updateSQL, -2) == ", ") {
$updateSQL = substr($updateSQL, 0, strlen($updateSQL)-2);
}
$updateSQL .= " WHERE `used`=".$tkey;
$rs = mysql_query($updateSQL, $conn) or die(mysql_error());
ob_end_clean();
header("Location: seriallist.php");
}
?>
<?php include ("header.php") ?>
<p><font face="Arial" size="3">Edit TABLE: serial<br><br><a href="seriallist.php">Back to List</a></font></p>
<script language="JavaScript" src="ew.js"></script>
<script language="JavaScript">
<!-- start Javascript
function EW_checkMyForm(EW_this) {
if (EW_this.x_serial && !EW_hasValue(EW_this.x_serial, "TEXT" )) {
if (!EW_onError(EW_this, EW_this.x_serial, "TEXT", "Invalid Field"))
return false;
}
if (EW_this.x_used && !EW_hasValue(EW_this.x_used, "TEXT" )) {
if (!EW_onError(EW_this, EW_this.x_used, "TEXT", "Invalid Field"))
return false;
}
return true;
}
// end JavaScript -->
</script>
<form onSubmit="return EW_checkMyForm(this);" action="serialedit.php" method="post">
<p>
<input type="hidden" name="a" value="U">
<input type="hidden" name="key" value="<?php echo $key; ?>">
<table width="85%" border="0" cellspacing="2" cellpadding="4" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#0000FF"><font color="#FFFFFF"><font face="Arial" size="3">serial</font> </font></td>
<td bgcolor="#F5F5F5"><font face="Arial" size="3"><b><?php echo $x_serial; ?></b><input type="hidden" name="x_serial" value="<?php echo htmlspecialchars(@$x_serial); ?>"></font> </td>
</tr>
<tr>
<td bgcolor="#0000FF"><font color="#FFFFFF"><font face="Arial" size="3">used</font> </font></td>
<td bgcolor="#F5F5F5"><font face="Arial" size="3"><input type="text" name="x_used" size="30" maxlength="10" value="<?php echo htmlspecialchars(@$x_used); ?>"></font> </td>
</tr>
</table>
<p>
<input type="submit" name="Action" value="EDIT">
</form>
<?php include ("footer.php") ?>