wright67uk Posted April 25, 2011 Share Posted April 25, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/234673-else-else-if-or-syntax-error/ Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2011 Share Posted April 25, 2011 Count the parentheses on this line. elseif ($Email == '' or (!filter_var($Email, FILTER_VALIDATE_EMAIL)) Quote Link to comment https://forums.phpfreaks.com/topic/234673-else-else-if-or-syntax-error/#findComment-1205940 Share on other sites More sharing options...
fugix Posted April 25, 2011 Share Posted April 25, 2011 yep looks like you need to add one more ending parenthesis on that line Quote Link to comment https://forums.phpfreaks.com/topic/234673-else-else-if-or-syntax-error/#findComment-1205942 Share on other sites More sharing options...
wright67uk Posted April 25, 2011 Author Share Posted April 25, 2011 <?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? Quote Link to comment https://forums.phpfreaks.com/topic/234673-else-else-if-or-syntax-error/#findComment-1205950 Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2011 Share Posted April 25, 2011 Another one missing at the end of the if( $Postcode == condition. Quote Link to comment https://forums.phpfreaks.com/topic/234673-else-else-if-or-syntax-error/#findComment-1205954 Share on other sites More sharing options...
spiderwell Posted April 25, 2011 Share Posted April 25, 2011 hehe beat me to it! also i thought you had to use || not OR or can you use either Quote Link to comment https://forums.phpfreaks.com/topic/234673-else-else-if-or-syntax-error/#findComment-1205955 Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2011 Share Posted April 25, 2011 Both OR and || are valid syntax. They have different precedence, though. Quote Link to comment https://forums.phpfreaks.com/topic/234673-else-else-if-or-syntax-error/#findComment-1205965 Share on other sites More sharing options...
wright67uk Posted April 25, 2011 Author Share Posted April 25, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/234673-else-else-if-or-syntax-error/#findComment-1205981 Share on other sites More sharing options...
wildteen88 Posted April 25, 2011 Share Posted April 25, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/234673-else-else-if-or-syntax-error/#findComment-1205988 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.