0

Hi ,i'm new to php & mysql. I'm tryin 2 build an online query runner and just started it. I am getting this error: Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in F:\wamp\www\chapter 3\ex-01\scripts\run_query.php on line 15

This is my code:

<?php

 require 'sqlconnect.php';

 $query_text = $_REQUEST['query'];
 $result = mysql_query($query_text); 

 if (!$result) {
 die("<p>Error in executing the SQL query " . $query_text . ": " .
 mysql_error() . "</p>");
 }
 echo "<p>Results from your query:</p>";
 echo "<ul>";
 while ($row=mysql_fetch_row($result)) {
 echo "<li>{$row[0]}</li>";
 }
 echo "</ul>";
?>

POINT IS SIMPLE QUERY LIKE "SHOW DATABASES" RUN SUCCESSFULLY.

vasanth kumar
  • 524
  • 1
  • 5
  • 18
user2559578
  • 133
  • 1
  • 10
  • Switch to PDO or MySqli..avoid mysql now..as a suggestion why don't you try to `echo $query_text` and `$result` to know what is pouring in? – swapnesh Jul 08 '13 at 06:23
  • replace this $result = mysql_query($query_text); with $result = mysql_query($query_text) or die(mysql_error()); – Rohit Choudhary Jul 08 '13 at 06:23
  • See [this answer](http://stackoverflow.com/a/11674313/250259) for how to troubleshoot this. – John Conde Jul 08 '13 at 13:28

1 Answers1

0

it seems your mysql_query returns false which is boolean, try

$result = mysql_query($query_text) or die(mysql_error());

and then

if ($result) {
// do you code
} 
vladkras
  • 15,313
  • 4
  • 42
  • 52