Parse error: syntax error, unexpected T_VARIABLE on line 107

Parse error: syntax error, unexpected T_VARIABLE on line 107

下面代码中的第107行是

$sql="INSERT INTO " $table_name " (confirm_code,name,password,email,address,phone,education,date_of_birth) VALUES 
        ('".$confirm_code."','".$name."','".$pwd."','".$email."','".$adres."','".$phno."','".$educon."','".$dob."') "; "

我有点意外T_VARIABLE;

<?php
if(isset($_POST['Register']))
{ 
    $name= $_POST['uname'];
    $pwd= $_POST['pswd'];
    $email= $_POST['email'];
    $phno= $_POST['phno']; 
    $adrs= str_replace("'","`",$_POST['adres']);
    $adres  =   $adrs;
    $educon= $_POST['educon']; 
    $dob= $_POST['dob'];
    $chkname    =   "select email from ".USREG." where email='".$email."'";
    $res        =       mysql_query($chkname, $con) or die(mysql_error());
    $chkresult=mysql_fetch_array($res);
    $uemail= $chkresult['email'];
     //print_r($uemail);die();
     include ('config.php');
     $table_name=temp_members_db;
     $confirm_code=md5(uniqid(rand()));
        if($uemail==$email)
        {
            echo ' <p style="color:red">Email <b> '.$email.' </b> Already exists</p>';
        }
        else
        {
            $sql="INSERT INTO " $table_name      "(confirm_code,name,password,email,address,phone,education,date_of_birth) VALUES 
             ('".$confirm_code."','".$name."','".$pwd."','".$email."','".$adres."','".$phno."','".$educon."','".$dob."') ";
             $result  = mysql_query($sql, $con) or die(mysql_error());
            if($result)
            {  
                $to=$email;
                echo '<p style="color:green"> '.$name.' Your Registration Success</p> <br/>'; 
                $subject    =   "your confirmation link here";
                            $headers  = 'MIME-Version: 1.0' . "\r\n";
                            $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  
                            $header = 'From: ShareLibrary <'.ADMIN_MAIL.'>' . "\r\n";  
                            $admMesg    =   $email." is registered "; 
                            $message = "your confrimation link \r\n";
                            $message = "click on this link to activae your account \r\n";
                            $message = "http://www.xxxxxx.in/confirmation.php?passkey=$confirm_code";
                            $sentmail = $mail($to,$subject,$message,$header);
           if($sentmail)
                {   
                    echo '<p style="color:green">registration details sent to  '.$email.' </p><br/>';
                }
                else
                {
                    echo '<p style="color:red">registration details sending to your mail was failed';
                }
            }
            else
            { 
                echo "<p>Registration FAILED</p>";
            }
        } 
    } 
?>

以上代码为用户注册表,注册完成后激活码将发送至用户注册邮箱。

我知道 T_VARIABLE 错误的发生主要是由于显示错误的前一行缺少分号或大括号。但我想我用分号结束了前一行并且我没有错过任何大括号。但我仍然收到这个意外的 t_variable 错误,我不知道它为什么会出现。请任何人帮助我解决这个问题

您缺少串联运算符:

 $sql="INSERT INTO " $table_name      "(confi
                   ^^^^^         ^^^^^
                   HERE          HERE

应该是

$sql="INSERT INTO " . $table_name . "(confi

PHP 也应该警告您 $table_name=temp_members_db;

您的字符串值 temp_members_db 周围缺少引号,如果不加引号,则 considered/treated 作为 constant

$table_name='temp_members_db';
  • 仅供参考,您也对 SQL injections 持开放态度。

$table_name 周围连接字符串时缺少点:

$sql = "INSERT INTO " . $table_name . "(confirm_code, name, password, email, address, phone, education, date_of_birth) VALUES ...