Copy link to clipboard
Copied
Hi:
Working with the DW Tutorial "Creating an event registration in PHP Part 2: Building the back end". Files are on my local server.
I have reg_update.php all set as far as I can tell. However, in the browser, the text fields, which I believe should be pre-filled from the db are not. And the changes I am making are not going to the database. I have redone the recordset, the update server behavior, and at least on the surface, it looks OK I think.
Can anyone see where I am going wrong? Thanks, Ned
<?php require_once('Connections/connEventReg.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE registrants SET RegFirstName=%s, RegLastName=%s, RegEmail=%s, RegDay=%s WHERE RegID=%s",
GetSQLValueString($_POST['RegFirstName'], "text"),
GetSQLValueString($_POST['RegLastName'], "text"),
GetSQLValueString($_POST['RegEmail'], "text"),
GetSQLValueString($_POST['RegDay'], "int"),
GetSQLValueString($_POST['RegID'], "int"));
mysql_select_db($database_connEventReg, $connEventReg);
$Result1 = mysql_query($updateSQL, $connEventReg) or die(mysql_error());
$updateGoTo = "reg.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_rsRegistrant = "-1";
if (isset($_GET['ID'])) {
$colname_rsRegistrant = $_GET['ID'];
}
mysql_select_db($database_connEventReg, $connEventReg);
$query_rsRegistrant = sprintf("SELECT * FROM registrants WHERE RegID = %s", GetSQLValueString($colname_rsRegistrant, "int"));
$rsRegistrant = mysql_query($query_rsRegistrant, $connEventReg) or die(mysql_error());
$row_rsRegistrant = mysql_fetch_assoc($rsRegistrant);
$totalRows_rsRegistrant = mysql_num_rows($rsRegistrant);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/relative_realty_admin.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Relative Realty</title>
<!-- InstanceEndEditable -->
<link href="../styles/main.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<link href="styles/main.css" rel="stylesheet" type="text/css" />
<!-- InstanceEndEditable -->
<style type="text/css">
td img {display: block;}
</style>
<!-- InstanceParam name="logout" type="boolean" value="true" -->
</head>
<body>
<div id="wrapper">
<div id="header">
<table border="0" cellpadding="0" cellspacing="0" width="760">
<!-- fwtable fwsrc="relative_realty_logo.png" fwpage="Page 1" fwbase="relative_realty_admin.jpg" fwstyle="Dreamweaver" fwdocid = "2023914168" fwnested="0" -->
<tr>
<td><img src="images/admin_images/spacer.gif" width="176" height="1" border="0" alt="" /></td>
<td><img src="images/admin_images/spacer.gif" width="47" height="1" border="0" alt="" /></td>
<td><img src="images/admin_images/spacer.gif" width="41" height="1" border="0" alt="" /></td>
<td><img src="images/admin_images/spacer.gif" width="91" height="1" border="0" alt="" /></td>
<td><img src="images/admin_images/spacer.gif" width="34" height="1" border="0" alt="" /></td>
<td><img src="images/admin_images/spacer.gif" width="109" height="1" border="0" alt="" /></td>
<td><img src="images/admin_images/spacer.gif" width="262" height="1" border="0" alt="" /></td>
<td><img src="images/admin_images/spacer.gif" width="1" height="1" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="7"><img name="relative_realty_admin_r1_c1" src="images/admin_images/relative_realty_admin_r1_c1.jpg" width="760" height="82" border="0" id="relative_realty_admin_r1_c1" alt="" /></td>
<td><img src="images/admin_images/spacer.gif" width="1" height="82" border="0" alt="" /></td>
</tr>
<tr>
<td rowspan="3"><img name="relative_realty_admin_r2_c1" src="images/admin_images/relative_realty_admin_r2_c1.jpg" width="176" height="33" border="0" id="relative_realty_admin_r2_c1" alt="" /></td>
<td><a href="login.php"><img name="home" src="images/admin_images/home.jpg" width="47" height="15" border="0" id="home" alt="" /></a></td>
<td rowspan="3"><img name="relative_realty_admin_r2_c3" src="images/admin_images/relative_realty_admin_r2_c3.jpg" width="41" height="33" border="0" id="relative_realty_admin_r2_c3" alt="" /></td>
<td rowspan="2"><a href="reg.php"><img name="registrants" src="images/admin_images/registrants.jpg" width="91" height="18" border="0" id="registrants" alt="" /></a></td>
<td rowspan="3"><img name="relative_realty_admin_r2_c5" src="images/admin_images/relative_realty_admin_r2_c5.jpg" width="34" height="33" border="0" id="relative_realty_admin_r2_c5" alt="" /></td>
<td><a href="present.php"><img name="relative_realty_admin_r2_c6" src="images/admin_images/relative_realty_admin_r2_c6.jpg" width="109" height="15" border="0" id="relative_realty_admin_r2_c6" alt="" /></a></td>
<td rowspan="3"><img name="relative_realty_admin_r2_c7" src="images/admin_images/relative_realty_admin_r2_c7.jpg" width="262" height="33" border="0" id="relative_realty_admin_r2_c7" alt="" /></td>
<td><img src="images/admin_images/spacer.gif" width="1" height="15" border="0" alt="" /></td>
</tr>
<tr>
<td rowspan="2"><img name="relative_realty_admin_r3_c2" src="images/admin_images/relative_realty_admin_r3_c2.jpg" width="47" height="18" border="0" id="relative_realty_admin_r3_c2" alt="" /></td>
<td rowspan="2"><img name="relative_realty_admin_r3_c6" src="images/admin_images/relative_realty_admin_r3_c6.jpg" width="109" height="18" border="0" id="relative_realty_admin_r3_c6" alt="" /></td>
<td><img src="images/admin_images/spacer.gif" width="1" height="3" border="0" alt="" /></td>
</tr>
<tr>
<td><img name="relative_realty_admin_r4_c4" src="images/admin_images/relative_realty_admin_r4_c4.jpg" width="91" height="15" border="0" id="relative_realty_admin_r4_c4" alt="" /></td>
<td><img src="images/admin_images/spacer.gif" width="1" height="15" border="0" alt="" /></td>
</tr>
</table>
</div>
<div id="middle"><!-- InstanceBeginEditable name="content" -->
<h1>Update</h1>
<p class="firstParagraph">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
<form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
<table width="500" border="0">
<tr>
<td width="150" class="formLabel">First Name:</td>
<td><input name="RegFirstName" type="text" id="RegFirstName" value="<?php echo $row_rsRegistrant['RegFirstName']; ?>" /></td>
</tr>
<tr>
<td class="formLabel">Last Name:</td>
<td><input name="RegLastName" type="text" id="RegLastName" value="<?php echo $row_rsRegistrant['RegLastName']; ?>" /></td>
</tr>
<tr>
<td class="formLabel">Email:</td>
<td><input name="RegEmail" type="text" id="RegEmail" value="<?php echo $row_rsRegistrant['RegEmail']; ?>" /></td>
</tr>
<tr>
<td class="formLabel">Days:</td>
<td><input name="RegDay" type="text" id="RegDay" value="<?php echo $row_rsRegistrant['RegDay']; ?>" />
Use -1 for both days</td>
</tr>
<tr>
<td width="150"><input name="RegID" type="hidden" id="RegID" value="<?php echo $row_rsRegistrant['RegID']; ?>" /></td>
<td><input type="submit" name="button" id="button" value="Update" /></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1" />
</form>
<p> </p>
<!-- InstanceEndEditable --></div>
<div id="footer">
<p><a href="#">Home</a> - <a href="#">Sales</a> - <a href="#">Rentals</a> - <a href="#">About Us</a> - <a href="logout.php">Log Out</a></p>
</div>
</div>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($rsRegistrant);
?>
Copy link to clipboard
Copied
The update form should be populated as a result of the URL parameter sent from the previous page. The code you have here shows that the parameter is $_GET['ID']. Check that the the previous page uses a form submitted using the GET method or a link that ends in a query string similar to this:
update.php?ID=3
PHP is case-sensitive. Check that the variable sent through the query string is uppercase. If not, change $_GET['ID'] to $_GET['id'].
Copy link to clipboard
Copied
Hi David:
Thanks for your help -- the Case was the problem, and id worked much better than ID. Unfortunately, the tutorial said to put ID, so hopefully Adobe will correct this.
My problem is that I am following these tutorials step by step, and I don't necessarily understand the concepts (such as URL Parameters) behind the directions. My plan is to re-read your Essential Guide once I finish these exercises. I was totally lost the first time through, so maybe it will make more sense now.
Thanks again!
Rgds, Ned
Copy link to clipboard
Copied
Nedward wrote:
Thanks for your help -- the Case was the problem, and id worked much better than ID. Unfortunately, the tutorial said to put ID, so hopefully Adobe will correct this.
I have checked the tutorial. It's correct. It looks as though you made a mistake on page 4 of the tutorial. On both pages, ID is in uppercase.
Copy link to clipboard
Copied
Right you are, David and I apologize for blaming the author.
However, I now have id consistently throughout instead of ID. But my delete page isn;t deleting, if you saw my other post. Comments appreciated!