Modifying Mysql DB

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jmaqu
Forum Newbie
Posts: 1
Joined: Mon Jan 12, 2004 6:47 pm

Modifying Mysql DB

Post by jmaqu »

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


Code: Select all

<?php session_start(); ?>
<?php if (@$HTTP_SESSION_VARS&#1111;"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&#1111;"key"];
if (empty($key)) &#123;
	$key = @$HTTP_POST_VARS&#1111;"key"];
&#125;
if (empty($key)) &#123;
	header("Location: seriallist.php");
&#125;

// get action
$a = @$HTTP_POST_VARS&#1111;"a"];
if (empty($a)) &#123;
	$a = "I";	//display with input box
&#125;

// get fields from form
$x_serial = @$HTTP_POST_VARS&#1111;"x_serial"];
$x_used = @$HTTP_POST_VARS&#1111;"x_used"];

// open connection to the database
$conn = mysql_connect(HOST, USER, PASS);
mysql_select_db(DB);
switch ($a)
&#123;
	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))) &#123;
     	ob_end_clean();
			header("Location: seriallist.php");
		&#125;

		// get the field contents
		$x_serial = @$row&#1111;"serial"];
		$x_used = @$row&#1111;"used"];
		mysql_free_result($rs);		
		break;
	case "U": // update
		$tkey = "'" . $key . "'";

		// get the form values
		$x_serial = @$HTTP_POST_VARS&#1111;"x_serial"];
		$x_used = @$HTTP_POST_VARS&#1111;"x_used"];

		// add the values into an array

		// serial
		$theValue = (!get_magic_quotes_gpc()) ? addslashes($x_serial) : $x_serial;
		$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
		$fieldList&#1111;"`serial`"] = $theValue;

		// used
		$theValue = (!get_magic_quotes_gpc()) ? addslashes($x_used) : $x_used;
		$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
		$fieldList&#1111;"`used`"] = $theValue;

		// update
		$updateSQL = "UPDATE `serial` SET ";
		foreach ($fieldList as $key=>$temp) &#123;
			$updateSQL .= "$key = $temp, ";			
		&#125;
		if (substr($updateSQL, -2) == ", ") &#123;
			$updateSQL = substr($updateSQL, 0, strlen($updateSQL)-2);
		&#125;
		$updateSQL .= " WHERE `used`=".$tkey;
  	$rs = mysql_query($updateSQL, $conn) or die(mysql_error());
		ob_end_clean();
		header("Location: seriallist.php");
&#125;		
?>
<?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) &#123;
if (EW_this.x_serial && !EW_hasValue(EW_this.x_serial, "TEXT" )) &#123;
            if (!EW_onError(EW_this, EW_this.x_serial, "TEXT", "Invalid Field"))
                return false; 
        &#125;
if (EW_this.x_used && !EW_hasValue(EW_this.x_used, "TEXT" )) &#123;
            if (!EW_onError(EW_this, EW_this.x_used, "TEXT", "Invalid Field"))
                return false; 
        &#125;
return true;
&#125;

// 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>&nbsp;</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>&nbsp;</td>
</tr>
<tr>
<td bgcolor="#0000FF"><font color="#FFFFFF"><font face="Arial" size="3">used</font>&nbsp;</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>&nbsp;</td>
</tr>
</table>
<p>
<input type="submit" name="Action" value="EDIT">
</form>
<?php include ("footer.php") ?>
Post Reply