-1

The following is a PHP code trying to print some statement. But all it does is print the following error:

Parse error: syntax error, unexpected T_STRING in C:\Program Files\Apache Group\Apache2\htdocs\chat_status.php on line 8

THE CODE:

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

?>
kamal0808
  • 515
  • 7
  • 21

2 Answers2

0

Change following line to:

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

Note the closing ".

Also note the comment from @jamie0726 (Thanks):

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

hek2mgl
  • 143,113
  • 25
  • 227
  • 253
  • hours of code gets your brain outta you head i guess! thanks. – kamal0808 Mar 26 '13 at 20:28
  • 2
    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 @Quentin 's links above. Thanks! :-) – herrjeh42 Mar 26 '13 at 20:41
0

try this

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

 ?>
echo_Me
  • 36,552
  • 5
  • 55
  • 77