|
-
Apr 1st, 2015, 05:50 PM
#1
Thread Starter
Hyperactive Member
[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_value, time() + (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
-
Apr 1st, 2015, 08:15 PM
#2
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.
-
Apr 2nd, 2015, 02:13 AM
#3
Thread Starter
Hyperactive Member
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
 Originally Posted by dclamp
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|