Parse error: syntax error, unexpected $end in

Discussion in 'PHP' started by neil_12s, Aug 17, 2010.

  1. #1
    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
     
    neil_12s, Aug 17, 2010 IP
  2. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #2
    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:
     
    Rainulf, Aug 17, 2010 IP
  3. neil_12s

    neil_12s Active Member

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    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
    -----------------------------------------------------------------------------



     
    neil_12s, Aug 17, 2010 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    If you don't use curly braces there, it'll only execute the FIRST expression after it. The rest will run as expected.
     
    nico_swd, Aug 18, 2010 IP
  5. neil_12s

    neil_12s Active Member

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #5
    Thanks Starcaller.

    I am very grateful.

    Wilfred
     
    neil_12s, Aug 18, 2010 IP