Unexpected else statement error

when i try to run this code i am getting an unexpected else statement error and i can’t seem to figure out why any help would be very much appriciated. It tells me the error is on line 23 which is

[php]

<?php ob_start(); ?> <?php if(empty ($_POST['firstname']) ||empty ($_POST['lastname']) ||empty ($_POST['email'])){ echo "

You must fill in your first name, last name and email address.

\n"; echo "

Please use your browser's back button to return to the form.

\n"; }//end if empty else { $db_name ="shellytestsite"; $con = @mysql_connect("mysql.shellytestsite.netwalker.us", "shellyingalls", "NaZUG@c+*hEf8"); if ($con===FALSE) { echo "

Unable to connect to the database server.

" . "Error code " . mysql_errno() . ": " . mysql_error() ."";} else{ //select the database $db = mysql_select_db($db_name, $con); if($db === FALSE){ echo "

Unable to connect to the database server.

" . "

Error code " . mysql_errno() . ": " . mysql_error() . "

";} } (Line 23) else { $db_table = "mailinglist"; $first=addslashes($_POST['firstname']); $last=addslashes($_POST['lastname']); $mail=($_POST['email']); $SQLstring="INSERT INTO $db_table(firstname, lastname, email) VALUES('$first, $last, $email)"; $QueryResult=mysql_query($SQLstring,$con); // test if data entered if (!mysql_error($con)) {//if ($QueryResult === TRUE) echo "

Your email has been added to our mailing list.

\n"; echo "

Thank you.

\n"; } else { echo "

Unable to add your information at this time. Please contact support.

\n"; } mysql_close($con); $con = FALSE; }//end if }//end else ?>

[/php]

hello shelly you doing a minor mistake that's why you are getting that error in below code you are using two time closing curly brackets "}" for if condition. replace below code [php] #replace below code if($db === FALSE){ echo "

Unable to connect to the database server.

" . "

Error code " . mysql_errno() . ": " . mysql_error() . "

";} } (Line 23) [/php]

use below modified code
[php]
#use below modified code
if($db === FALSE){
echo “

Unable to connect to the database server.

” . "

Error code " . mysql_errno() . ": " . mysql_error() . “

”;
}
[/php]

i hope this will helpful for you.
Reply your feedback…
SR

ok thanks that worked but i had to add another curley bracket to the end

Hello shelly, can you explain what exactly you are looking. where and how you want to add extra curly brackets? ~~SR~~

It is now working when i took the extra curley bracket before line 23 i had to close it at the end of the code now it seems to be working.

hello shelly, OK, i think it's happening because of browser cache. but i think it's working completely fine now for you. :D :) ~~SR~~
Sponsor our Newsletter | Privacy Policy | Terms of Service