-1

I'm new to web applications, I was trying to write this simple query

$query2 = "SELECT * from sections WHERE  starting = ' 8:00 ' And day = ' Monday ' AND section = '$section' AND campus = '$campus' AND year = '$year'  ";

$result = mysql_query($query2) or die(mysql_error($conn));
$count2 = mysql_num_rows($result);
if($count2==0){
    echo'<td color=orange>&nbsp;</td>';
    }
     while ($row = mysqli_fetch_array($result)) {
        echo "<td>".$row['course']."</td>";}

However I'm getting this error. I tried to figure it out but I couldn't. Could someone plz help me

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'And day = ' Monday ' AND section = 'A' AND campus = 'Nabatieh' AND year = 'Bache' at line 1

dimlucas
  • 5,040
  • 7
  • 37
  • 54
  • 2
    `year = 'Bache'`? sure? My guess is, year is defined as int (for a good reason), but you pass a string – Jeff May 21 '16 at 21:54
  • Also, you're mixing mysql and mysql. That won't work. Please [don't use `mysql_*`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php?rq=1); the `mysql_*` functions are outdated, [deprecated](http://us3.php.net/manual/en/intro.mysql.php), and insecure. Use [`MySQLi`](http://us3.php.net/manual/en/book.mysqli.php) or [`PDO`](http://us3.php.net/manual/en/intro.pdo.php) instead. – elixenide May 21 '16 at 22:01
  • If my first comment didn't point you to the error you've got, you'd need to show: how/where `$year` is defined and your table-definition. – Jeff May 21 '16 at 22:05

3 Answers3

0

I think your SQL server is not entertaining case insensitive query designs . I mean it is differentiating between And & AND ... So i suggest modifying your query like.. $query2 = "SELECT * from sections WHERE starting = ' 8:00 ' AND day = ' Monday ' AND section = '$section' AND campus = '$campus' AND year = '$year' ";

Maddy Blacklisted
  • 1,190
  • 1
  • 7
  • 17
  • If so, then Please bother to show your database table design because I think you are probably sending a string value to the database instead of an integer or something... – Maddy Blacklisted May 21 '16 at 22:23
0

Dude, another possibility is that you didn't give a space after the first value before And... Do double check on it please...

Because the error shown has displayed 'And ... Instead... it should be ' And ....

Maddy Blacklisted
  • 1,190
  • 1
  • 7
  • 17
-2

It could be the "And" after the "starting" var is in upper and lower. Although Mysql is not necessarily case sensitive, you shouldn't mix upper and lower.

see here... http://dev.mysql.com/doc/refman/5.7/en/identifier-case-sensitivity.html

Gatesey
  • 34
  • 6