Jump to content

Recommended Posts

Post your entire NEW code so that I can see what you are really running.   Hopefully I am going to recognize ALL of my code and only have to be concerned with what you added.   If that is not the case then why bother?

Hi Ginerjm

Here is the code:

<?php
session_start();
error_reporting (E_ALL);
ini_set('display_errors','1');
$errors = array();
require "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 = $pdo->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: &#163;</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>
	";
exit();

Thank for your help!

The error is on line 21 - missing a } at the end of the line.

The opening { on line 20 is currently matched with the closing } on line 75;

You also have a superfluous } on line 96 (so they are all in pairs, jus not matched correctly).

Ginerjm

Here is the section with lines in error:

<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>

See the attached picture for which lines are in error.

thank you!

Var_errors.jpg

Which line exactly is 131?  Show it HERE

Please do the following:

1 - you should have only one '<form' tag and only one '</form' tag.  Please confirm

2 - the contents of that form between the 2 form tags should have a submit button ie.

"<input type='submit'" .  Confirmed?

3 - the line 131 should be this one by my reckoning:

<form method='POST'>
	<label><b>First Name: </b>
	<br>
    <!---  LINE 131 BELOW -->
	<input type='text' name='fname' size='20' maxlength='40' value='$fname' required>
	</label>
	

If all 3 of my question are true then I have no idea what else you have in your code that is causing the problem.  I'm guessing it is something to do with the initialization of all your php vars when you don't detect a POST array.  One thing we could do is move that block to define all the vars before you begin any code.

Edited by ginerjm

Hi Ginerjm

1> Yes I do have the correct form tags,

2>The closing one also is after the submit.

3> Yes that is the line 131

I am assuming the vars are the following:

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);}
        

if($_SERVER["REQUEST_METHOD"] == "POST")

As you can see that is just above the $_SERVER["REQUEST_METHOD] == "POST"

is this what you mean?

I tried that and I still get the same errors?

Would it be because I am using htmlentities?

Can't think of anything else!

4 minutes ago, rocky48 said:

Can't think of anything else!

You have been told exactly where the problem is ...

3 hours ago, Barand said:

The error is on line 21 - missing a } at the end of the line.

The opening { on line 20 is currently matched with the closing } on line 75;

You also have a superfluous } on line 96 (so they are all in pairs, jus not matched correctly).

 

Ginerjm

I am trying to expand my knowledge by doing a sort course via Udemy.

I have just got to the bit about showing errors, so I tried putting it into my code, here is the code:

$ErrorInformation=$conn->errorInfo();
print_r($ErrorInformation);

When I run the code it fails with the following message:

Quote

Notice: Undefined variable: conn in /homepages/30/d593365489/htdocs/MFC1066/senior_data5.php on line 8

Fatal error: Uncaught Error: Call to a member function errorInfo() on null in /homepages/30/d593365489/htdocs/MFC1066/senior_data5.php:8 Stack trace: #0 {main} thrown in /homepages/30/d593365489/htdocs/MFC1066/senior_data5.php on line 8

That's the same sort of error I am getting with the items in my form!

I copied the code you posted and got all your errors on fname etc. I then made those 2 changes and all the errors went away.

This is your code with those two { } errors fixed. This doesn't mean you have more that aren't showing yet.

<?php
session_start();
error_reporting (E_ALL);
ini_set('display_errors','1');
$errors = array();
#require "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 = $pdo->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: &#163;</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>
    ";

 

and the error-free output...

image.thumb.png.53f0e6890d2209954112d0ca99e475c2.png

I will copy your code tomorrow. I did change the missing curly brackets on line 21. I may have misunderstood I thought the one on line 20 was the opening bracket for the missing one on line 21.  Is this correct or not?

 I removed the superfluous closing bracket on line 75.

I said the superfluous one was on line 96.

The curly bracket was being opened on 20 and should've been closed at the end of line 21. Because of the missing one on 21, the next one that the { on line 20 could be paired with was the one on line 75. This was completely screwing up the logic and processing flow of your code so lines that should have executed didn't - hence some variables weren't defined.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.