Can someone kindly help me tosolve this problem. My php error message is Parse error: syntax error, unexpected $end in The php program is update.php ----------------------------------------------------------------------------- <html> <head> <title>Table editing</title> </head> <body> <?php $user = "jmbecoo4_neil12"; $pass = "marians321C"; $db = "jmbecoo4_email"; $link = mysql_connect ( "localhost",$user,$pass ); if (! $link) die ( "couldn't connect to MySQL" ); { print "Successfully connected to server<P>" ; } mysql_select_db ( $db ) or die ( "couldn't open $db: ".mysql_error() ); { print "Successfully selected database \"$db\"<P>"; } mysql_close ( $link ); $fname=$_POST[ 'fname' ]; $lname=$_POST[ 'lname' ]; $email=$_POST[ 'email' ]; $query="INSERT INTO contact ( id,fname,lname,email ) values ( 'NULL', ' ".$fname." ', '".$lname." ', ' ".$email." ' )"; mysql_query( $query ) or die ( 'Error updating database' ); { echo "Database Updated With: ".$fname. " ".$lname. " ".$email."; } ?> </body> </html> ------------------------------------------------------------------------------- Thanks Wilfred
Try this: <html> <head> <title>Table editing</title> </head> <body> <?php $user = "jmbecoo4_neil12"; $pass = "marians321C"; $db = "jmbecoo4_email"; $link = mysql_connect ("localhost", $user, $pass ); if (!$link) die( "couldn't connect to MySQL" ); else echo "Successfully connected to server<br />"; $lol = mysql_select_db ($db) if(!$lol) echo "couldn't open $db: ".mysql_error( ); else echo "Successfully opened db.<br />"; $fname=$_POST['fname']; $lname=$_POST['lname']; $email=$_POST['email']; $query="INSERT INTO contact ( id,fname,lname,email ) values ('NULL', '$fname', '$lname', '$email')"; $lol = mysql_query($query); if(!$lol) echo "couldn't insert to $db: ".mysql_error( ); else { echo "Successfully inserted to db.<br />"; echo "Database Updated With: $fname $lname $email."; } mysql_close ($link); ?> </body> </html> PHP:
Thank you Can you explain $lol = mysql_select_db ($db) if(!$lol) echo "couldn't open $db: ".mysql_error( ); else echo "Successfully opened db.<br />"; 1. What is (!$lol) 2. Do you think that we should braces after (!$lol) and before "else" Also after else and after acho statement? There was error message to say Parse error: syntax error, unexpected T_IF in /home/jmbecoo4/public_html/testmysql/update.php on line 14 Wilfred -----------------------------------------------------------------------------
If you don't use curly braces there, it'll only execute the FIRST expression after it. The rest will run as expected.