PHP echo代码不起作用

时间:2013-03-26 20:25:38

标签: php mysql ajax

以下是试图打印一些语句的PHP代码。但它所做的只是打印以下错误:

解析错误:语法错误,第8行的C:\ Program Files \ Apache Group \ Apache2 \ htdocs \ chat_status.php中的意外T_STRING

代码:

<?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);
}

?>

2 个答案:

答案 0 :(得分:0)

将以下行更改为:

$check_table=mysql_query("SELECT * FROM `$row[studentid]"."to"."$_GET[id]`");

请注意结束"

注意来自@ jamie0726的评论(谢谢):

  

在任何情况下,请不要在查询中使用$ _GET。这是一个严重的安全错误(SQL注入,例如使用您的代码删除数据库非常容易)。你可以轻松避免这种情况。看看

答案 1 :(得分:0)

试试这个

    <?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);
 }

 ?>
相关问题