<?php
mysql_connect("localhost","root","");
mysql_select_db("hftwmvirtualdb");
$Booknum = mysql_real_escape_string($_POST['Booknum']);
$Chapternum = mysql_real_escape_string($_POST['Chapternum']);
$Versenum = mysql_real_escape_string($_POST['Versenum']);
$sql = mysql_query("SELECT `VERSETEXT` FROM `booktable` WHERE `BOOKID` = $Booknum AND `CHAPTERID` = $Chapternum AND `VERSENO` = $Versenum");
echo mysql_error();
while($row=mysql_fetch_assoc($sql));
print(json_encode($row));
mysql_close();
?>
I am trying to use posted data from an android application to trigger a query and retrieve the results from the mysql database. The Table has 4 columns, and I'm trying to retrieve the value in the third column by defining the values in the first 3 columns. Each time i clicked the button, I get the parsing error to find out my PHP script was not processing the SQL query. When running the scriptthrough the browser I get the messages:
- Undefined index: Booknum in C:\wamp\www\GetVerse.php on line 4
- Undefined index: Chapternum in C:\wamp\www\GetVerse.php on line 5
- Notice: Undefined index: Versenum in C:\wamp\www\GetVerse.php on line 6
- 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
CHAPTERID
= ANDVERSENO
=' at line 1 - Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\GetVerse.php on line 9.
I understand i get the warning messages 1-3 is because I did not submit the post data but the latter I don't know how to fix as I have tried using the correct syntax, I tried removing "=" for "like" and that failed also. What is the problem?.
mysql_*
functions are no longer maintained and community has begun the deprecation process . Instead you should learn about prepared statements and use either PDO or MySQLi. If you cannot decide, this article will help to choose. If you want to learn, here is a good PDO-related tutorial. – vascowhite Aug 13 '12 at 14:32BOOKID='$Booknum'
– Waygood Aug 13 '12 at 14:34while($row[]=mysql_fetch_assoc($sql));
– Karan Punamiya Aug 13 '12 at 14:38