Hi,
When trying to update this table, I'm not getting any errors thrown back, but for some reason it's just not updating the table. I suspect it's to do with the script below (memberedit.php) which isn't sending the ID (or anything else!) to the second script (memberupdate.php). I've truncated the drop down menus to keep this a little shorter. I've a horrid suspicion I'm going to have to rewrite this from scratch, which I'd rather not do as updating is the only thing left i need to be able to do at the moment!
Any helpful suggestions please?!
<?php // Require the classes
require_once('../sypphp/includes/DbConnector.php');
require_once('../sypphp/includes/Validator.php');
// Create an object (instance) of the DbConnector and Validator
$connector = new DbConnector();
$validator = new Validator();
// EDIT SECTIONS ////////////////////////////////////////////////////////////////////
if ($HTTP_GET_VARS['action'] == 'edit'){
// Store the section ID to be updated in a variable
$memberID = $HTTP_GET_VARS['ID'];
// Validate the memberID, and if it's ok update the section
if ( $validator->validateGeneral($memberID,'ID') ){
// The validator returned true, so go ahead and delete the section
$result = $connector->query("SELECT * FROM members WHERE ID = $memberID");
$row = $connector->fetchArray($result);
//INSERT THE UPDATE FORM WITH RETRIEVED INFORMATION HERE
?>
<form action="memberupdate.php" method="post" enctype="multipart/form-data" name="updatemem" id="updatemem">
<table width="60%" border="0" align="center" cellpadding="4" cellspacing="0">
<tr>
<td align="left" valign="middle">First name: </td>
<td align="left"><input name="firstname" type="text" id="firstname" size="45" value="<?php echo $row['firstname'] ?>"></td>
</tr>
<tr>
<td align="left" valign="middle">Surname: </td>
<td align="left"><input name="surname" type="text" id="surname" size="45" value="<?php echo $row['surname'] ?>"</td>
</tr>
<tr>
<td align="left" valign="middle">Date of Birth</td>
<td align="left"><SELECT NAME=dobmonth id="dobmonth" align=top>
<OPTION selected value="<?php echo $row['dobmonth'].'>'.$row['dobmonth']?>"
<OPTION VALUE=January>January
<OPTION VALUE=February>February
</SELECT>
<SELECT NAME=dobday id="dobday" align=top>
<OPTION selected value=<?php echo $row['dobday'].'>'.$row['dobday']?>
<OPTION VALUE=01>1
</SELECT>
<SELECT NAME=dobyear id="dobyear" align=top>
<OPTION VALUE=1959>1959
<OPTION selected value=<?php echo $row['dobyear'].'>'.$row['dobyear']?>
<OPTION VALUE=1960>1960
</select>
</td>
</tr>
<tr>
<td align="left" valign="middle">Address Line 1 </td>
<td align="left"><input name="address1" type="text" id="address1" size="45" value="<?php echo $row['address1'] ?>"></td>
</tr>
<tr>
<td align="left" valign="middle">Address Line 2</td>
<td align="left"><input name="address2" type="text" id="address2" size="45" value="<?php echo $row['address2'] ?>"></td>
</tr>
<tr>
<td align="left" valign="middle">Address Line 3</td>
<td align="left"><input name="address3" type="text" id="address3" size="45" value="<?php echo $row['address3'] ?>"></td>
</tr>
<tr>
<td align="left" valign="middle">Postcode</td>
<td align="left"><input name="postcode" type="text" id="postcode" size="45" value="<?php echo $row['postcode'] ?>"></td>
</tr>
<tr>
<td align="left" valign="middle">Email:</td>
<td align="left"><input name="email" type="text" id="email" size="45" value="<?php echo $row['email'] ?>"></td>
</tr>
<tr>
<td align="left" valign="middle">Company/University</td>
<td align="left"><input name="company" type="text" id="company" size="45" value="<?php echo $row['company'] ?>"></td>
</tr>
<tr>
<td align="left" valign="middle">Job Role/Course</td>
<td align="left"><input name="jobrole" cols="45" rows="6" id="jobrole" value="<?php echo $row['jobrole'] ?>"></td>
</tr>
<tr>
<td align="left" valign="middle">Add to Jobs List?</td>
<td align="left"><input name="jobslist" type="checkbox" id="jobslist" value="<?php echo $row['jobslist'] ?>" checked></td>
</tr>
<tr>
<td align="left" valign="middle">Add to Events List?</td>
<td align="left"><input name="eventslist" type="checkbox" id="eventslist" value="<?php echo $row['eventslist'] ?>" checked></td>
</tr>
<tr>
<td align="left" valign="middle">London or Oxford?</td>
<td align="left"><SELECT NAME=london id="london" align=top>
<OPTION value="<?php echo $row['london'] ?>">London
<OPTION VALUE=Oxford>Oxford
</select></td>
</tr>
<tr>
<td align="left" valign="middle">Join Date</td>
<td align="left"><SELECT NAME=joinmonth id="joinmonth" align=top>
<OPTION selected value=<?php echo $row['joinmonth'].'>'.$row['joinmonth']?>
<OPTION VALUE=January>January
<OPTION VALUE=December>December
</SELECT>
<SELECT NAME=joinday id="joinday" align=top>
<OPTION selected value=<?php echo $row['joinday'].'>'.$row['joinday']?>
<OPTION VALUE=01>1
</SELECT>
<SELECT NAME=joinyear id="joinyear" align=top>
<OPTION VALUE=1900>1900
<OPTION VALUE=1959>1959
<OPTION selected value=<?php echo $row['joinyear'].'>'.$row['joinyear']?>
<OPTION VALUE=1960>1960
<OPTION VALUE=2005>2005
</select></td>
</tr>
<tr>
<td align="left" valign="middle">Expiry Date</td>
<td align="left"><SELECT NAME=expmonth id="expmonth" align=top>
<OPTION selected value=<?php echo $row['expmonth'].'>'.$row['expmonth']?>
<OPTION VALUE=January>January
</SELECT>
<SELECT NAME=expday id="expday" align=top>
<OPTION selected value=<?php echo $row['expday'].'>'.$row['expday']?>
<OPTION VALUE=01>1
</SELECT>
<SELECT NAME=expyear id="expyear" align=top>
<OPTION VALUE=1959>1959
<OPTION selected value=<?php echo $row['expyear'].'>'.$row['expyear']?>
<OPTION VALUE=1960>1960
</select></td>
</tr>
<tr>
<td align="left" valign="middle">Membership Number</td>
<td align="left"><input name="memnum" type="text" id="memnum" size="45" value="<?php echo $row['memnum']?>"></td>
</tr>
</table>
<input type="hidden" name="id" id="id" value=<?php echo $row['id']?> />
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<?php
}else{
// The validator returned false, meaning there was a problem
echo "Couldn't update. There was a problem with: ".$validator->listErrors();
}
}
?>
</body></html>
memberupdate.php:
<?php // Require the classes
require_once('../sypphp/includes/DbConnector.php');
require_once('../sypphp/includes/Validator.php');
// Create an object (instance) of the DbConnector and Validator
$connector = new DbConnector();
$validator = new Validator();
if ($_POST['Submit']) {
$firstname=$HTTP_POST_VARS['firstname'];
$surname=$HTTP_POST_VARS['surname'];
$dobmonth=$HTTP_POST_VARS['dobmonth'];
$dobday=$HTTP_POST_VARS['dobday'];
$dobyear=$HTTP_POST_VARS['dobyear'];
$address1=$HTTP_POST_VARS['address1'];
$address2=$HTTP_POST_VARS['address2'];
$address3=$HTTP_POST_VARS['address3'];
$postcode=$HTTP_POST_VARS['postcode'];
$email=$HTTP_POST_VARS['email'];
$jobrole=$HTTP_POST_VARS['jobrole'];
$jobslist=$HTTP_POST_VARS['jobslist'];
$eventslist=$HTTP_POST_VARS['eventslist'];
$london=$HTTP_POST_VARS['london'];
$joinmonth=$HTTP_POST_VARS['joinmonth'];
$joinday=$HTTP_POST_VARS['joinday'];
$joinyear=$HTTP_POST_VARS['joinyear'];
$expmonth=$HTTP_POST_VARS['expmonth'];
$expday=$HTTP_POST_VARS['expday'];
$expyear=$HTTP_POST_VARS['expyear'];
$memnum=$HTTP_POST_VARS['memnum'];
// Create an SQL query (MySQL version)
// The 'addslashes' command is used 5 lines below for added security
// Remember to use 'stripslashes' later to remove them (they are inserted in front of any
// special characters
$insertQuery = "UPDATE members SET firstname='$firstname', surname = '$surname', dobday = '$dobday', dobmonth = '$dobmonth', dobyear = '$dobyear', address1 = '$address1', address2 = '$address2', address3 = '$address3', postcode = '$postcode', email = '$email', company = '$company', jobrole = '$jobrole', jobslist = '$jobslist', eventslist = '$jobslist', london = '$london', joinmonth = '$joinmonth', joinday = '$joinday', joinyear = '$joinyear', expmonth = '$expmonth', expday = '$expday', expyear = '$expyear', memnum = '$memnum' WHERE ID ='$id'";
// Save the form data into the database
if ($result = $connector->query($insertQuery)){
// It worked, give confirmation
echo '<center><b>Member Updated</b></center><br>';
} else {
// It hasn't worked so stop. Better error handling code would be good here!
exit('<center>Sorry, there was an error saving to the database: '.mysql_error().'</center>');
}
?>