Hi, I've modified your script in order to fit the requirements of my database but I am now getting the following errors:
Here is the code for my php editing file:
/*
EDIT RECORD
*/
// if the 'id' variable is set in the URL, we know that we need to edit a record
if (isset($_GET['account_code']))
{
// if the form's submit button is clicked, we need to process the form
if (isset($_POST['submit']))
{
// make sure the 'id' in the URL is valid
if (is_string($_POST['account_code']))
{
// get variables from the URL/form
$account_code = htmlentities($_POST['account_code'], ENT_QUOTES);
$forename = htmlentities($_POST['forename'], ENT_QUOTES);
$surname = htmlentities($_POST['surname'], ENT_QUOTES);
$address_1 = htmlentities($_POST['address_1'], ENT_QUOTES);
$address_2 = htmlentities($_POST['address_2'], ENT_QUOTES);
$town_city = htmlentities($_POST['town_city'], ENT_QUOTES);
$county = htmlentities($_POST['county'], ENT_QUOTES);
$postcode = htmlentities($_POST['postcode'], ENT_QUOTES);
$company_name = htmlentities($_POST['company_name'], ENT_QUOTES);
$email = htmlentities($_POST['email'], ENT_QUOTES);
$telephone = htmlentities($_POST['telephone'], ENT_QUOTES);
$mobile = htmlentities($_POST['mobile'], ENT_QUOTES);
// check that firstname and lastname are both not empty
if ($forename == '' || $surname == '')
{
// if they are empty, show an error message and display the form
$error = 'ERROR: Please fill in all required fields!';
renderForm($account_code, $forename, $surname, $address_1, $address_2, $town_city, $county, $postcode, $company_name, $email, $telephone, $mobile, $error);
}
else
{
/*$result = mysqli_query($cxn,"UPDATE tbl_billing_info SET account_code='$account_code',forename'$forename',surname='$surname',address_1='$address_1',address_2='$address_2',town_city='$town_city',county='$county',postcode='$postcode',company_name='$company_name',email='$email',telephone='$telephone',mobile='$mobile' WHERE account_code='$account_code'"); or die ("Could not connect to the database server<br />\n" . mysqli_connect_error());*/
// if everything is fine, update the record in the database
if ($stmt = $cxn->prepare("UPDATE tbl_billing_info SET account_code = ?, forename = ?, surname = ?, address_1 = ?, address_2 = ?, town_city = ?, county = ?, postcode = ?, company_name = ?, email = ?, telephone = ?, mobile = ? WHERE account_code= ?"))
{
$stmt->bind_param("s,s,s,s,s,s,s,s,s,s,s,s", $account_code, $forename, $surname, $address_1, $address_2, $town_city, $county, $postcode, $company_name, $email, $telephone, $mobile);
$stmt->execute();
$stmt->close();
}
// show an error message if the query has an error
else
{
echo "ERROR: could not prepare SQL statement.";
}
// redirect the user once the form is updated
header("Location: billing_info_editing_newANDedit.php");
}
}
// if the 'id' variable is not valid, show an error message
else
{
echo "Error!";
}
}
// if the form hasn't been submitted yet, get the info from the database and show the form
else
{
// make sure the 'id' value is valid
if (is_string($_GET['account_code']) && $_GET['account_code'] != NULL)
{
// get 'id' from URL
$account_code = $_GET['account_code'];
// get the record from the database
if($stmt = $cxn->prepare("SELECT account_code,forename,surname, address_1, address_2, town_city, county, postcode, company_name, email, telephone, mobile FROM tbl_billing_info WHERE account_code= ?"))
{
$stmt->bind_param("s", $account_code);
$stmt->execute();
$stmt->bind_result($account_code, $forename, $surname, $address_1, $address_2, $town_city, $county, $postcode, $company_name, $email, $telephone, $mobile);
$stmt->fetch();
// show the form
renderForm($account_code, $forename, $surname, $address_1, $address_2, $town_city, $county, $postcode, $company_name, $email, $telephone, $mobile, NULL);
$stmt->close();
}
// show an error if the query has an error
else
{
echo "Error: could not prepare SQL statement";
}
}
// if the 'id' value is not valid, redirect the user back to the view.php page
else
{
header("Location: billing_info_editing_newANDedit.php");
}
}
}
For Quote 1:
All fields that I use in the table are VCHAR datatype except for 'town_city' and 'postcode' which are ENUM datatypes and 'postcode' which is CHAR. I know that this binding method only uses a few data types such as string, decimal etc. and maybe the ENUM data type is causing the trouble here. I have been reading up on this but I can't find any info on the web which suggests that passing an ENUM type as a string would cause any issues. I'm relatively new to PHP and MySQL.
For Quote 2:
Not sure what is causing this exactly, I'm aware that outputting echo statements earlier on the script can cause this error and I haven't included the entirety of my code on this example. Just the piece that is causing the issue.
Any help on this would be appreciated.
Thanks