2013-03-26 92 views
-1

以下是試圖打印某些語句的PHP代碼。但它是所有打印以下錯誤:PHP回顯代碼不能正常工作

解析錯誤:語法錯誤,在C意想不到T_STRING:\ Program Files文件\ Apache的集團\的Apache2 \ htdocs目錄\ chat_status.php上線8

的代碼:

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

?> 
+4

語法高亮使你的錯誤遠 – 2013-03-26 20:26:14

+1

這是因爲在C有意想不到的T_STRING: \ Program Files \ Apache Group \ Apache2 \ htdocs \ chat_status.php第8行 – 2013-03-26 20:26:20

+0

是的,關閉第8行的雙引號 – JakeCataford 2013-03-26 20:27:17

回答

0

更改以下行:

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

注收盤"

而且從@ jamie0726(感謝)的評論:

Please do not use $_GET in your query under any circumstances. That's a severe security mistake (SQL injection, it's very easy to delete your database for example with your code.). You can avoid this easily. Check out

+0

小時的代碼讓你的大腦不在你頭上我猜!謝謝。 – kamal0808 2013-03-26 20:28:57

+0

歡迎您;) – hek2mgl 2013-03-26 20:31:18

+2

請不要在任何情況下在您的查詢中使用$ _GET。這是一個嚴重的安全錯誤(SQL注入,使用你的代碼很容易刪除你的數據庫)。你可以輕鬆避免這種情況。查看@Quentin上面的鏈接。謝謝! :-) – herrjeh42 2013-03-26 20:41:31

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

?>