Page 1 of 1

Repeating fields

Posted: Thu Feb 19, 2004 3:48 pm
by James138
Hi,
Im trying to modify my members details on my website. I have got a menu that drops down and lists all the membersIDs which are saved in the database. Then the details about the individual members should load up in the fields beneath once the MemberID is clicked on. But this is not working. Has anyone got any ideas or suggestions?

Cheers

Posted: Thu Feb 19, 2004 5:24 pm
by Dr Evil
Show us some code. Give us a bit more info.

Posted: Thu Feb 19, 2004 6:18 pm
by James138
I have posted the code for my page. The table is called member table.
Hope this helps


<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE membertable SET Title=%s, Surname=%s, Forename=%s, Handicap=%s, `Home Number`=%s, `Work Number`=%s WHERE MemberID=%s",
GetSQLValueString($HTTP_POST_VARS['Title'], "text"),
GetSQLValueString($HTTP_POST_VARS['Title'], "text"),
GetSQLValueString($HTTP_POST_VARS['Surname'], "text"),
GetSQLValueString($HTTP_POST_VARS['Forename'], "text"),
GetSQLValueString($HTTP_POST_VARS['Handicap'], "text"),
GetSQLValueString($HTTP_POST_VARS['Home_Number'], "text"),
GetSQLValueString($HTTP_POST_VARS['Work_Number'], "text"));

mysql_select_db($database_james, $james);
$Result1 = mysql_query($updateSQL, $james) or die(mysql_error());

$updateGoTo = "../delete%20User/Administratoroptions.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}

mysql_select_db($database_james, $james);
$query_updatetable = "SELECT * FROM membertable ORDER BY MemberID ASC";
$updatetable = mysql_query($query_updatetable, $james) or die(mysql_error());
$row_updatetable = mysql_fetch_assoc($updatetable);
$totalRows_updatetable = mysql_num_rows($updatetable);
?>

<p align="left"><img src="../../Templates/background1_r1_c1.gif" width="800" height="151"><br>
<img src="../../Templates/background1_r2_c1.gif" width="150" height="449" align="left"></p>


<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">MemberID:</td>
<td>
<select name="select" size="1">
<?php
do {
?>
<option value="<?php echo $row_updatetable['MemberID']?>"<?php if (!(strcmp($row_updatetable['MemberID'], $row_updatetable['MemberID']))) {echo "SELECTED";} ?>><?php echo $row_updatetable['MemberID']?></option>
<?php
} while ($row_updatetable = mysql_fetch_assoc($updatetable));
$rows = mysql_num_rows($updatetable);
if($rows > 0) {
mysql_data_seek($updatetable, 0);
$row_updatetable = mysql_fetch_assoc($updatetable);
}
?>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Title:</td>
<td><input type="text" name="Title" value="<?php echo $row_updatetable['Title']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Surname:</td>
<td><input type="text" name="Surname" value="<?php echo $row_updatetable['Surname']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Forename:</td>
<td><input type="text" name="Forename" value="<?php echo $row_updatetable['Forename']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Handicap:</td>
<td><input type="text" name="Handicap" value="<?php echo $row_updatetable['Handicap']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Home Number:</td>
<td><input type="text" name="Home_Number" value="<?php echo $row_updatetable['Home Number']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Work Number:</td>
<td><input type="text" name="Work_Number" value="<?php echo $row_updatetable['Work Number']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><input type="submit" value="Update Record"></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="MemberID" value="<?php echo $row_updatetable['MemberID']; ?>">
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($updatetable);
?>