Page 1 of 1

Parse error- unexpected $end , help me solve this problem!

Posted: Mon Aug 17, 2009 10:48 pm
by rizalp1
//This is the program I wrote to update information from user in the file mypage.php?do="SOMETHING" and I found the Unexpected $end parse error! Can someone help me with the code? THanks!!




<?php

function displaylogin(){
//readily available to use when needed to

?>

Please Enter your Login information again!
<form action='login.php' method='post'>
<table><tr><td>Email: <td><input type='text' name='email'><br>
<tr><td>Password: <td><input type='password' name='password'>
<tr><td><input type='submit' value='continue'></table>
</form>
<a href='signup.php' target='_self'>Create new login ID</a>

<?php

}

if (isset($_COOKIE['email'])){
$email = $_COOKIE['email'];

switch ($_REQUEST['do']) {
// out of various options from the previous page, checked by the counter "do" the user selects one
case "update":

// if do=update
?>

<form id='update' action='mypage.php' method='post'>
<table>
<tr><td colspan="2">To change Name or email, please contact webmaster
<tr><td><td>
<tr><td>Address: <td><input type='text' name='address'>
<tr><td>Phone No: <td><input type='text' name='phone'>
<tr><td>Major: <td><input type='text' name='major'>
<tr><td>Semesters<td><input type='text' name='semesters'>
<tr><td>Working at (Optional): <td><input type='text' name='employer'>
<input type='hidden' name='do' value='updated'>
</table>
</form>

<?php
break;

case "updated":

$connection= mysql_connect("","username","password");

if (!$connection){die ("Error encountered. Please contact webmaster");}

mysql_select_db("database");

$tablename= "information";

$query= "create table if not exists ".$tablename." (email varchar(40) Not Null Primary Key, address varchar(50), phone varchar(20), major varchar(25), semesters varchar(15), employer varchar(40) )";

$result= mysql_query($query);

if (!$result){
die ("Error!!");
}

$query= 'select * from $tablename where email="$email"';
$result= mysql_query($query);

if (mysql_num_rows($result)== 0){ // we wish to create new record only if update takes place for the first time.
$address= $_REQUEST['address'];
$phone= $_REQUEST['phone'];
$major= $_REQUEST['major'];
$semesters= $_REQUEST['semesters'];
$employer= $_REQUEST['employer'];
$query="INSERT INTO $tablename VALUES('". $email ."','". $address ."','". $phone ."','". $major ."','". $semesters ."','". $employer ."')";

$result= mysql_query($query);
if (!$result){
die ("Error occured! Contact webmaster" );
}
}
else{

// we can use UPDATE if email address already exists in the record!
}
echo "Your information has been saved!";
echo "<a href='login.php'>;
// closing switch
}
// closing if
}
else
{
displaylogin();
}

?>

</body>
</html>

Re: Parse error- unexpected $end , help me solve this problem!

Posted: Mon Aug 17, 2009 11:32 pm
by requinix
Get yourself an editor with syntax highlighting.

Code: Select all

<?php
 
function displaylogin(){
    //readily available to use when needed to
 
?>
 
Please Enter your Login information again!
<form action='login.php' method='post'>
<table><tr><td>Email: <td><input type='text' name='email'><br>
<tr><td>Password: <td><input type='password' name='password'>
<tr><td><input type='submit' value='continue'></table>
</form>
<a href='signup.php' target='_self'>Create new login ID</a>
 
<?php
 
}
 
if (isset($_COOKIE['email'])){
    $email = $_COOKIE['email'];
 
    switch ($_REQUEST['do']) {
        // out of various options from the previous page, checked by the counter "do" the user selects one
        case "update":
 
            // if do=update
?>
 
<form id='update' action='mypage.php' method='post'>
<table>
<tr><td colspan="2">To change Name or email, please contact webmaster
<tr><td><td>
<tr><td>Address: <td><input type='text' name='address'>
<tr><td>Phone No: <td><input type='text' name='phone'>
<tr><td>Major: <td><input type='text' name='major'>
<tr><td>Semesters<td><input type='text' name='semesters'>
<tr><td>Working at (Optional): <td><input type='text' name='employer'>
<input type='hidden' name='do' value='updated'>
</table>
</form>
 
<?php
            break;
 
        case "updated":
 
            $connection= mysql_connect("","username","password");
 
            if (!$connection){die ("Error encountered. Please contact webmaster");}
 
            mysql_select_db("database");
 
            $tablename= "information";
 
            $query= "create table if not exists ".$tablename." (email varchar(40) Not Null Primary Key, address varchar(50), phone varchar(20), major varchar(25), semesters varchar(15), employer varchar(40) )";
 
            $result= mysql_query($query);
 
            if (!$result){
                die ("Error!!");
            }
 
            $query= 'select * from $tablename where email="$email"';
            $result= mysql_query($query);
 
            if (mysql_num_rows($result)== 0){ // we wish to create new record only if update takes place for the first time.
                $address= $_REQUEST['address'];
                $phone= $_REQUEST['phone'];
                $major= $_REQUEST['major'];
                $semesters= $_REQUEST['semesters'];
                $employer= $_REQUEST['employer'];
                $query="INSERT INTO $tablename VALUES('". $email ."','". $address ."','". $phone ."','". $major ."','". $semesters ."','". $employer ."')";
 
                $result= mysql_query($query);
                if (!$result){
                    die ("Error occured! Contact webmaster" );
                }
            }
            else{
 
                // we can use UPDATE if email address already exists in the record!
            }
            echo "Your information has been saved!";
            echo "<a href='login.php'>;
    // closing switch
    }
// closing if
}
else
{
    displaylogin();
}
 
?>
 
</body>
</html>
 

Re: Parse error- unexpected $end , help me solve this problem!

Posted: Mon Aug 17, 2009 11:53 pm
by rizalp1
what kind of editor would be best for me? (I am PHP amateur!)

Re: Parse error- unexpected $end , help me solve this problem!

Posted: Tue Aug 18, 2009 12:00 am
by requinix
Depends whether you want an editor or a full-blown IDE.

There is no "best". Search around the forum - that question has been asked many times.

Re: Parse error- unexpected $end , help me solve this problem!

Posted: Tue Aug 18, 2009 3:20 am
by Cirdan
If you are on Windows, get Programmer's Notepad or Notepad++
If you are on Mac, I would recommend TextMate or Coda