Results 1 to 3 of 3

Thread: [RESOLVED] Parse error: syntax error, unexpected '$name' (T_VARIABLE)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    352

    Resolved [RESOLVED] Parse error: syntax error, unexpected '$name' (T_VARIABLE)

    Hi I m trying to play around with some code to get a grasp of how to insert a cookie so the browser can identify a user after sign up. However in my attempt I was met by the above mentioned error.
    PHP Code:
    $name="";
    $email="";
    $msg_to_user="";
    if (
    $_POST['name']!=""){
     include_once 
    "connect_to_mysql.php";
     
    $name$_POST['name'];
     
    $email$_POST['email'];
     
     
    $sql mysql_query("SELECT*FROM users where email ='$email'");
     
    $numsRows mysql_num_rows($sql);
     
     if(!
    $email) {
         
    $msg_to_user='<br/></br><h4><font color= "FF0000">Please input a Valid Email Address '$name' </font></h4>'
              
    } else if ($numRows 0){
        
    $msg_to_user='<br/></br><h4><font color= "FF0000"> '$email' is already in the system </font></h4>'

    else {
        
    $sql_insert=mysql_query('INSERT INTO users (name,email)')
                                
    VALUES('$name','$email') or die (mysql_error())
        
    $msg_to_user='<br/></br><h4><font color= "FF0000">Thanks '$name' you have been added successfully</font></h4>'
        
    $cookie_name "'$name'";
        
    $cookie_value "$email";
    setcookie($cookie_name$cookie_valuetime() + (86400 30), "/"); // 86400 = 1 day
    $name="";
    $email=""
    Could someone kindly tell me what I might not be doing right ?
    The line in question in the above code is
    PHP Code:
    $msg_to_user='<br/></br><h4><font color= "FF0000">Please input a Valid Email Address '$name' </font></h4>' 
    Thanks

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Parse error: syntax error, unexpected '$name' (T_VARIABLE)

    You need to use a period / decimal point to concatenate that string. You can also encapsulate the entire string with double quotes and use the string name alone.

    PHP Code:
    $msg_to_user='<br/></br><h4><font color= "FF0000">Please input a Valid Email Address ' $name ' </font></h4>';

    // or: 

    $msg_to_user="<br/></br><h4><font color= 'FF0000'>Please input a Valid Email Address {$name} </font></h4>";   
    //I also changed the font color quotes. 
    Its also not recommended to put very much HTML in php Strings. It is considered good practice to separate PHP from HTML as much as possible.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    352

    Re: Parse error: syntax error, unexpected '$name' (T_VARIABLE)

    Thanks so much didnt have a look at it that way . It was worth the experience. Cheers
    Quote Originally Posted by dclamp View Post
    You need to use a period / decimal point to concatenate that string. You can also encapsulate the entire string with double quotes and use the string name alone.

    PHP Code:
    $msg_to_user='<br/></br><h4><font color= "FF0000">Please input a Valid Email Address ' $name ' </font></h4>';

    // or: 

    $msg_to_user="<br/></br><h4><font color= 'FF0000'>Please input a Valid Email Address {$name} </font></h4>";   
    //I also changed the font color quotes. 
    Its also not recommended to put very much HTML in php Strings. It is considered good practice to separate PHP from HTML as much as possible.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width