tobyheywood
IS-IT--Management
Hi folks,
I am creating a form on a web page which contains (initially) a users details. From here the user is able to alter any of the details they wish, such as name, address, etc.
I am using the following code but am experiencing problems. I'm sure it is something simple but...
I sure the problem relates to the potentially lazy way I'm attemping to update the records, is it possible to use variables to specify a $_POST variable?
At the moment the code does not contain validation code but will do once I'm happy that the underly code works.
Would I be better off validating the users input and running a individual update query for each field?
I recieve the following error
Notice: Undefined index: CTitle in filename...
Thank you in advance.
Toby Heywood
I am creating a form on a web page which contains (initially) a users details. From here the user is able to alter any of the details they wish, such as name, address, etc.
I am using the following code but am experiencing problems. I'm sure it is something simple but...
I sure the problem relates to the potentially lazy way I'm attemping to update the records, is it possible to use variables to specify a $_POST variable?
At the moment the code does not contain validation code but will do once I'm happy that the underly code works.
Would I be better off validating the users input and running a individual update query for each field?
Code:
$link = connMyDB($dbh, $dbu, $dbp, $dab);
if(!empty($_POST['update'])) {
// Ensure all required fields are completed
$fields = array('CTitle','CFName','CLName','CAddr1','CCity','CProv','CPCode','CCountry','CTel','CEmail','CURL');
echo '<p class="Txt2Red">';
// initialise err check variable
$errcheck = "0";
foreach ($fields as $fs) {
if (!empty($_POST[$fs])) {
switch ($fs) {
case "CTitle":
echo 'You must enter your Title.<br>';
break;
case "CFName":
echo 'You must enter your first name(s).<br>';
break;
case "CLName":
echo 'You must enter your last name.<br>';
break;
case "CAddr1":
echo 'You must enter the first line of your address<br>';
break;
case "CCity":
echo 'Please enter the Town or City name<br>';
break;
case "CProv":
echo 'Please enter the county name<br>';
break;
case "CPCode":
echo 'Please enter your postal code<br>';
break;
case "CCountry":
echo 'Please enter your country of residence<br>';
break;
case "CTel":
echo 'Please enter a daytime telephone number<br>';
break;
case "CEmail":
echo 'Please enter your CURRENT WORKING email address';
break;
}
} else {
$errcheck = '1';
}
}
echo '</p>';
// run update query
if ($_POST['update'] == '1' AND $errcheck == '1') {
foreach($fields as $fs) {
$upquery = "UPDATE customer SET CTitle='". $_POST[$fs] . "' WHERE AccRef ='" . $_COOKIE['CPV'] . "';";
}
$result = mysqli_query($link, $upquery)
or die(mysqli_error($link));
}
}
$query = "SELECT * FROM customer WHERE AccRef = '" . $_COOKIE['CPV'] . "';";
$result = mysqli_query($link, $query);
$row = mysqli_fetch_row($result);
I recieve the following error
Notice: Undefined index: CTitle in filename...
Thank you in advance.
Toby Heywood