SQL query to AJAX not working, directly entered works fine

Geekygirl

New Member
An SQL query gives no output through AJAX page when variables are passed in the query. Even the count of number of rows gives zero (0). An \[code\]echo\[/code\] of the same query with the passed variables shows as having values. When copy and pasting the same (replacing) from the browser page to the query in the AJAX page it gives a result.The code is as follows (first SQL code in AJAX page with variables as parameter):\[code\]$qu="SELECT DISTINCT bk.bookname,bk.author,bk.publisher,bk.edition,bk.description,lam.article_name,bk.keywords,bk.qtyinstock FROM lib_article_master lam, lib_book_cd_master bk WHERE bk.bookname='$arr[2]' AND bk.author='$arr[3]' AND bk.publisher='$arr[4]' AND bk.article_id=lam.article_id";//here $arr[2],$arr[3],$arr[4] are variables from another query for comparison in AJAX page $r=QrySelect($qu);echo " <br> ".$qu;//query is echoed in browserecho "<br>count : ".mysql_num_rows($r);//count of number of rows$arr1=mysql_fetch_array($r); ?> <table width="97%" border="0" > <tr <td width="11%"><div align="left"><strong>Description </strong></div></td> </tr> </table> <textarea name="txt_Keywords" style="width:90%; height:90px"><?php echo $arr1[4]; ?></textarea>\[/code\]And the output is nothing.The query, when taken from the browser and put back in code along with values for variables we are getting an output.\[code\]$qu="SELECT DISTINCT bk.bookname,bk.author,bk.publisher,bk.edition,bk.description,lam.article_name,bk.keywords,bk.qtyinstock FROM lib_article_master lam, lib_book_cd_master bk WHERE bk.bookname='Java Complete Reference' AND bk.author='Martin D Leuthen' AND bk.publisher='ABS Publications' AND bk.article_id=lam.article_id";//here $arr[2],$arr[3],$arr[4] are replaced as per browser output$r=QrySelect($qu);echo " <br> ".$qu;//query is echoed in browserecho "<br>count : ".mysql_num_rows($r);//count of number of rows$arr1=mysql_fetch_array($r); ?> <table width="97%" border="0" > <tr <td width="11%"><div align="left"><strong>Description </strong></div></td> </tr> </table> <textarea name="txt_Keywords" style="width:90%; height:90px"><?php echo $arr1[4]; ?></textarea>\[/code\]We are getting an output for the above code with correct number of rows from the the database. Any help will be great.
 
Back
Top