I'm new to PDO and am not yet familiar with the language.
I am designing a form and am having problems with the prepare statement.
The error is on this line:
$stmt = $conn->prepare($sql);
The $conn is my connection code and $sql is an INSERT query.
The data for the query is obtained from a form within this file using $_POST.
Here is the complete file:
session_start();
error_reporting (E_ALL);
ini_set('display_errors','1');
$errors = array();
$conn='';
require_once "conn/connect_seniorform.php";
// MORE PHP CODE IF ANY
if($_SERVER["REQUEST_METHOD"] == "POST")
{ // read the inputs
if (isset ($_POST['fname'])){
$fname = htmlentities($_POST['fname'],ENT_QUOTES);}
if (isset ($_POST['sname'])){
$sname = htmlentities($_POST['sname'],ENT_QUOTES);}
if (isset ($_POST['email'])){
$email = htmlentities($_POST['email'],ENT_QUOTES);}
if (isset ($_POST['addr'])){
$addr = htmlentities($_POST['addr'],ENT_QUOTES);}
if (isset ($_POST['phone'])){
$phone = htmlentities($_POST['phone'],ENT_QUOTES);}
if (isset ($_POST['mob'])){
$mob = htmlentities($_POST['mob'],ENT_QUOTES); }
if (isset($_POST['bmfa_no'])){
$bmfa_no = htmlentities($_POST['bmfa_no'],ENT_QUOTES);}
if (isset($_POST['caa_no'])){
$caa_no = htmlentities($_POST['caa_no'],ENT_QUOTES);}
if (isset ($_POST['rewd'])){
$rewd = htmlentities($_POST['rewd'],ENT_QUOTES);}
if (isset ($_POST['fam'])){
$fam = htmlentities($_POST['fam'],ENT_QUOTES);}
if (isset($_POST['ctry'])){
$ctry = htmlentities($_POST['ctry'],ENT_QUOTES);}
if (isset($_POST['ctry_bmfa'])){
$ctry_bmfa = htmlentities($_POST['ctry_bmfa'],ENT_QUOTES);}
if (isset ($_POST['bdf'])){
$bdf = htmlentities($_POST['bdf'],ENT_QUOTES);}
if (isset($_POST['payopt'])){
$payopt = htmlentities($_POST['payopt'],ENT_QUOTES);}
if (isset ($_POST['payopt'])){
$pay = htmlentities($_POST['pay'],ENT_QUOTES);}
if (isset ($_POST['date'])){
$date = htmlentities($_POST['date'],ENT_QUOTES);}
if (isset ($_POST['sign'])){
$sign = htmlentities($_POST['sign'],ENT_QUOTES);}
// process the data now
if (count($errors) == 0)
{
$sql = "INSERT INTO senior_dat(fname,sname,email,dob,addr,phone,mob,bmfa_no,caa_no,rewd,fam,ctry,ctry_bmfa,bdf,payopt,pay,date,sign)
VALUES (:fname, :sname, :email,:dob, :addr, :phone, :mob, :bmfa_no, :caa_no, :rewd, :fam, :ctry, :ctry_bmfa, :bdf, :payopt, :pay, :date, :sign)";
$stmt = $conn->prepare($sql);
$parms = array(
'fname'=>$fname,
'sname'=>$sname,
'email'=>$email,
'addr'=>$addr,
'phone'=>$phone,
'mob'=>$mob,
'bmfa_no'=>$bmfa_no,
'caa_no'=>$caa_no,
'rewd'=>$rewd,
'fam'=>$fam,
'ctry'=>$ctry,
'ctry_bmfa'=>$ctry_bmfa,
'bdf'=>$bdf,
'payopt'=>$payopt,
'pay'=>$pay,
'date'=>$date,
'sign'>$sign
);
if (!$stmt->execute($parms))
$errors[] = "Insert query did not run";
else
$errors[] = "Your entries have been accepted";
}
}
else // no inputs yet
{
$fname = '';
$sname = '';
$email = '';
$addr = '';
$phone = '';
$mob = '';
$bmfa_no = '';
$caa_no = '';
$rewd = '';
$fam = '';
$ctry = '';
$ctry_bmfa = '';
$bdf = '';
$pay_opt = '';
$pay = '';
$date = '';
$sign = '';
}
// Done with the inputs - redisplay the form screen with the messages we produced.
//
// implode the errrors array to show the result message or the errors
$errmsg = implode('<br>', $errors);
echo "
<!DOCTYPE html>
<html lang='en'>
<head>
<style type='text/css'>
#form_box
{
position:relative;
float:left;
margin:3% 1%;
padding:5px;
border:2px solid black;
}
.red{color:red;}
</style>
</head>
<body>
";
echo "
<div id='form_box'>
<center>
<h1>SENIOR RENEWAL FORM</h1>
</center>
";
if(!empty($errmsg))
echo "<p class='red'>$errmsg</p>";
echo "
<form method='POST'>
<label><b>First Name: </b>
<br>
<input type='text' name='fname' size='20' maxlength='40' value='$fname' required>
</label>
<br>
<label><b>Surname: </b>
<br>
<input type='text' name='sname' size='20' maxlength='40' value='$sname' required>
</label>
<br>
<label><b>Email: </b>
<br>
<input type='text' name='email' size='20' maxlength='40' value='$email' required>
</label>
<br><br>
<label><b>Address: </b>
<br>
<input type='textarea' name='addr' rows='4' cols='50 value='$addr' required>
</label>
<br>
<label><b>Phone number:</br>
<input type='tel' name='phone' 'min=12' max=16' value='$phone' required>
</label>
<br>
<label> <b>Mobile number:</br>
<input type='tel' name='mob' 'min=12' 'max=16' value'$mob' required>
</label>
<br>
<label BMFA No:
<input type='number' name='bmfa_no' value='$bmfa_no' required>
</label>
<br>
<label CAA Operator No:
<input type='text' name='caa_no' value='$caa_no' required><br>
</label>
<label Do you wish that the club obtains your BMFA membership, Insurance & CAA renewal:
<select name='club_membership' id='club_membership'>
<option value='Select Yes or No'> </option>
<option value='NO'>NO</option>
<option value='YES'>YES</option>
</select>
</label>
<br>
<label for='Ctry'>Are you a Country Member:</label>
<select name='Ctry' id='Ctry'>
<option value='blank'> </option>
<option value='NO'>NO</option>
<option value='YES'>YES</option>
</select>
<br>
<label for='caa'>If you answered YES to the previous question,. have you a current BMFA and CAA membership:</label>
<select name='caa' id='caa'>
<option value='blank'> </option>
<option value='NO'>NO</option>
<option value='YES'>YES</option>
<option value='na'>N/A</option>
</select>
<br>
<label for='rewd'>Do you wish to purchase a BMFA Membership/Reward Card:</label>
<select name='rewd' id='rewd'>
<option value='blank'> </option>
<option value='NO'>NO</option>
<option value='YES'>YES</option>
</select>
<br>
<label for='fam'>Are you a family member:</label>
<select name='fam' id='fam'>
<option value='blank'> </option>
<option value='NO'>NO</option>
<option value='YES'>YES</option>
</select>
<br>
<label for='bdf'>Do you wish to join the British Drone flyers Association, instead of the BMFA:</label>
<select name='bdf' id='bdf'>
<option value='blank'> </option>
<option value='NO'>NO</option>
<option value='YES'>YES</option>
</select>
<p>Please note that if you join the BDF you can also fly fixed wing/ helicopters as well!</p>
<br>
<label for='pay_opt'>Ho do you wish to pay:</label>
<select name='pay_opt' id='pay_opt'>
<option value='blank'> </option>
<option value='chq'>CHEQUE</option>
<option value='csh'>CASH</option>
<option value='bacs'>BACS</option>
</select>
<br>
<p><b>Payment required: £</b><input type='text' name='pay' size='20' maxlength='40'/></p>
<br>
<p style='background-color:tomato;'>I apply for membership of the 1066 Model Flying Club and agree to abide by the rules.
By doing so agree to allow the club to use your details in respect of the GDPR regulations for the processing of your renewal, a copy of which can be found on the club website members page.
</p>
<br>
<label for='date'>Date:</label>
<input type='text' id='date' name='date'
pattern='[0-9]{2}/[0-9]{2}/[0-9]{4}'
required>
<br>
<label for='sign'>Sign here:</label>
<input type='text' id='sign' name='sign'
required>
<br>
<input type='submit' value='Submit'>
</form>
</div>
";
enter code here
Can anyone help?