0

i have a mysql database name cstudents with table students and sid,sname,sdiv and passyr as the table columns. i intend to print this entire table. here is the code i tried:

$con3=mysql_connect(DB_HOST1,DB_USER1,DB_PASSWORD1) or die ("failed to connect to mysql".mysql_error());
$db=mysql_select_db(DB_NAME1,$con3) or die ("failed to connect to mysql".mysql_error());
$query = "SELECT sid, sname, rollno, passyr FROM cstudents.student;
$result = mysql_query($query) or die ('Error:'.mysql_error($query));
while ($row = mysql_fetch_assoc($result,mysql_both)) {
    echo $row['sid'];
    echo $row['sname'];
    echo $row['sdiv'];
    echo $row['passyr'];
}

executing this gives: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

please help!

JanLeeYu
  • 981
  • 2
  • 9
  • 24
coderdj
  • 21
  • 2

1 Answers1

0

You have missed closing double quotes in your query, instead of:

$query = "SELECT sid, sname, rollno, passyr FROM cstudents.student;

must be:

$query = "SELECT sid, sname, rollno, passyr FROM cstudents.student";

And one suggestion: start using mysqli_* functions instead of already depreciated mysql_*.

mitkosoft
  • 5,262
  • 1
  • 13
  • 31
  • thanks for that suggestion. but now it gives this error:mysql_error() expects parameter 1 to be resource, string given – coderdj Mar 31 '16 at 10:50
  • you need to change ALL functions, including `mysql_error`, should be `mysqli_error($con3)`. – mitkosoft Mar 31 '16 at 10:51