PHP回显代码不工作
下面是一段PHP代码,它试图打印一些语句。但它所做的只是打印以下错误: 分析错误:语法错误,第8行的C:\Program Files\Apache Group\Apache2\htdocs\chat_status.php中出现意外的T_字符串 守则:PHP回显代码不工作,php,mysql,ajax,Php,Mysql,Ajax,下面是一段PHP代码,它试图打印一些语句。但它所做的只是打印以下错误: 分析错误:语法错误,第8行的C:\Program Files\Apache Group\Apache2\htdocs\chat_status.php中出现意外的T_字符串 守则: <?php session_start(); $con=mysql_connect("localhost","hi","hello"); mysql_select_db("my_db",$con); $check_table=mysql_qu
<?php
session_start();
$con=mysql_connect("localhost","hi","hello");
mysql_select_db("my_db",$con);
$check_table=mysql_query("SELECT * FROM `$row[studentid]"."to"."$_GET[id]`);
if($check_table!=FALSE)
{
$asd="no suggestion";
echo $asd;
}
else
{
$result1=mysql_query("SELECT * FROM students WHERE email='$_SESSION[user_name]'");
$row=mysql_fetch_array($result1);
$create_table="CREATE TABLE `$row[studentid]"."to"."$_GET[id]`(post_number int not null
auto_increment,primary key(post_number),data text(20000))";
$result=mysql_query($create_table,$con);
}
?>
将以下行更改为:
$check_table=mysql_query("SELECT * FROM `$row[studentid]"."to"."$_GET[id]`");
注意关闭“
另请注意@jamie0726的评论(谢谢):
在任何情况下,请不要在查询中使用$\u GET。这是一个严重的安全错误(SQL注入,很容易用代码删除数据库)。您可以很容易地避免这种情况。请签出
试试这个
<?php
session_start();
$con=mysql_connect("localhost","hi","hello");
mysql_select_db("my_db",$con);
$check_table=mysql_query("SELECT * FROM '$row[studentid]'.'to'.'$_GET[id]' ");
if($check_table!=FALSE)
{
$asd="no suggestion";
echo $asd;
}
else
{
$result1=mysql_query("SELECT * FROM students WHERE email='$_SESSION[user_name]'");
$row=mysql_fetch_array($result1);
$create_table="CREATE TABLE '$row[studentid]'.'to'.'$_GET[id]' (post_number int not null
auto_increment,primary key(post_number),data text(20000))";
$result=mysql_query($create_table,$con);
}
?>
语法高亮显示会提示您的错误,因为第8行的C:\Program Files\Apache Group\Apache2\htdocs\chat_status.php中有一个意外的T_字符串。是的,请关闭第8行的双引号。检查引号是否成对。您正在使用,并且应该使用。您还容易受到现代API的影响,这会使您的操作变得更简单在任何情况下,请不要在查询中使用$\u GET。这是一个严重的安全错误(SQL注入,很容易用代码删除数据库)。您可以很容易地避免这种情况。请查看上面@Quentin的链接。谢谢!:-)