2016-05-01 236 views
-1

我在代码中收到解析错误。解析错误:语法错误,意外的T_ENCAPSED_AND_WHITESPACE,期待T_STRING或T_VARIABLE或T_NUM_STRING

我的代码是:

$query="INSERT into tbl_result('result_uname','result_date','result_subject','result_rightans','result_wrongans','result_marks') values ('$uname','$curdate','$subject','10','10','$_SESSION['marks']')"; 
    if(mysql_query($query)) 
    { 
    header("Location: result.php"); 
    ?> 
    <script>alert("Your Answers Submitted...");</script> 
    <?php 
    } 
    else 
    { 
    ?> 
     <script>alert('Error While Submitting...');</script> 
    <?php 
    } 
+1

**警告**:如果您刚刚学习PHP,请勿使用[ 'mysql_query'](http://php.net/manual/en/function.mysql-query.php)界面。这是非常可怕和危险的,它在PHP 7中被删除了。[PDO的替代品并不难学](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps -pdo-for-database-access /)以及[PHP The Right Way](http://www.phptherightway.com/)等指南介绍了最佳实践。你的用户参数是**不是** [正确转义](http://bobby-tables.com/php),并且有[SQL注入漏洞](http://bobby-tables.com/)可以被利用。 – tadman

回答

0

该位:

'$_SESSION['marks']' 

使用单引号内的单引号。这是行不通的,整个事情已经在双引号内。你将不得不使用字符串连接。或者,将$_SESSION['marks']分配给一个变量,并在您的查询中使用该变量,就像您已经使用$ uname,$ curdate等做的一样。

相关问题