Jump to content

Else, Else if, OR, ?!? Syntax error!


wright67uk

Recommended Posts

Im trying to validate each of my form fields one by one;

 

<form action="#" method="post">
Name: 		<input type="text" name="Name" maxlength="50"/><br />
Phone:	    <input type="text" name="Phone" maxlength="50"/><br />
Email: 		<input type="text" name="Email" maxlength="50"/><br />
Postcode: 	<input type="text" name="Postcode" maxlength="50"/><br />
Web Address: <input type="text" name="Website" maxlength="50"/><br /><br />
<select name="drop_1" id="drop_1"> 
<option value="" selected="selected" disabled="disabled">Select a Category</option>  
<?php getTierOne(); ?>
</select> 
<span id="wait_1" style="display: none;">
<img alt="Please Wait" src="ajax-loader.gif"/>
</span>
<span id="result_1" style="display: none;"></span> <br />

</form>
</p>
<p>
<?php if(isset($_POST['submit']))
{
$drop = mysql_real_escape_string($_POST['drop_1']);
$tier_two = mysql_real_escape_string($_POST['Subtype']);
echo "You selected ";
echo $drop." & ".$tier_two;
$Name = mysql_real_escape_string($_POST["Name"]);
$Phone = mysql_real_escape_string($_POST["Phone"]);
$Email = mysql_real_escape_string($_POST["Email"]);
$Postcode = mysql_real_escape_string($_POST["Postcode"]);
$Postcode = strtoupper(str_replace(' ','',$Postcode));
$Website = mysql_real_escape_string($_POST["Website"]);
if($Name == '')
{
	die('<br> You did not complete the name field, please try again');
}
elseif  ($Phone == '' or (!preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $Phone))
{  // LINE 74 HERE 
	die('<br> You completed the telephone field incorrectly, please try again');
}		
elseif  ($Email == '' or (!filter_var($Email, FILTER_VALIDATE_EMAIL))
{
	die('<br> You completed the Email field incorrectly, please try again');
}									   
elseif  ($Postcode == '' or (!preg_match("/^[A-Z]{1,2}[0-9]{2,3}[A-Z]{2}$/",$Postcode) || 
		                 !preg_match("/^[A-Z]{1,2}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{2}$/",$Postcode) || 
					     !preg_match("/^GIR0[A-Z]{2}$/",$Postcode))
{
	die('<br> You did not complete the Postcode field correctly, please try again');
}		  
elseif  ($Website == '')
{
	die('<br>The website field was empty, please try again');
}
}

 

my code returns an error;

 

Parse error: syntax error, unexpected '{' on line 74

 

I thought this was how else if statements were used, but I am learning and would love a bit of guidance should anyone be kind enough?

 

Link to comment
Share on other sites

<?php if(isset($_POST['submit']))
{
$drop = mysql_real_escape_string($_POST['drop_1']);
$tier_two = mysql_real_escape_string($_POST['Subtype']);
echo "You selected ";
echo $drop." & ".$tier_two;
$Name = mysql_real_escape_string($_POST["Name"]);
$Phone = mysql_real_escape_string($_POST["Phone"]);
$Email = mysql_real_escape_string($_POST["Email"]);
$Postcode = mysql_real_escape_string($_POST["Postcode"]);
$Postcode = strtoupper(str_replace(' ','',$Postcode));
$Website = mysql_real_escape_string($_POST["Website"]);
if($Name == '')
{
	die('<br> You did not complete the name field, please try again');
}
elseif  ($Phone == '' or (!preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $Phone)))
{	//LINE74
	die('<br> You completed the telephone field incorrectly, please try again');
}		
elseif  ($Email == '' or (!filter_var($Email, FILTER_VALIDATE_EMAIL)))
{
	die('<br> You completed the Email field incorrectly, please try again');
}									   
elseif  ($Postcode == '' or (!preg_match("/^[A-Z]{1,2}[0-9]{2,3}[A-Z]{2}$/",$Postcode) || 
		                 !preg_match("/^[A-Z]{1,2}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{2}$/",$Postcode) || 
					     !preg_match("/^GIR0[A-Z]{2}$/",$Postcode))
{
	die('<br> You did not complete the Postcode field correctly, please try again');
}		  
elseif  ($Website == '')
{
	die('<br>The website field was empty, please try again');
}
}

 

Im still getting the same error on line 74, Im not sure if its more frustrating that Im making a mistake, or the fact that I cant see where im going wrong.  Further reading?

 

Ive read that w3schools is a bad place to learn php,any good places I should check out?

Link to comment
Share on other sites

Just a quick thanks for pointing out missing parenthesis.

After all that the postcode validator didnt even work anyway  >:(

 

Is there an online parenthesis checker I can use? I dont want to be wasting peoples time, on silly misatakes!

Use a better edit which has bracket matching support.

Link to comment
Share on other sites

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.