0

I have a database which has edit buttons on each entry but I get this error when trying to edit an item.

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /editentry.php on line 32

Here is the line in question and files corresponding to the problem.

$order = "SELECT * FROM Missions WHERE MissionNumber='$id'";

Missions.php labels all the entries with the edit button next to them - http://pastebin.com/VbTzUMDP

editentry.php is the page where the editing should take place where the error occurs - http://pastebin.com/fj7y9GFW

Also I am aware that this code has the chance of being SQL injected, but this is only some testing code for the moment with a page that can only be accessed by me.

4 Answers4

1

Try changing it to add the connection in your mysql_query() before you mysql_fetch_array():

 $con = mysql_connect($hostname, $username, $password) OR DIE ("Unable to
       connect to database! Please try again later.");
 mysql_select_db($dbname,$con);
 $data = mysql_query("SELECT * FROM Missions ORDER BY CashPayout DESC",$con) 
 or die(mysql_error());
 $info = mysql_fetch_array( $data );

By the way mysqli and PDO is preferred as it is more safe and secure.

Edper
  • 8,869
  • 1
  • 25
  • 46
0

When error in query then this type of error is show.. Try This:-

$id = $_GET['id'];
$order = "SELECT * FROM Missions WHERE MissionNumber = '".$id."' ";
Sandesh
  • 353
  • 2
  • 8
0

mysql_fetch_array() FALSE on failure or when there are no more rows. you can use back tick in your query and check , the value of $id you are getting or not.

$order = "SELECT * FROM `Missions` WHERE `MissionNumber` = '$id'";
Dinesh
  • 3,886
  • 4
  • 20
  • 33
0

There is an error in your query, use below code of line instead:

$order = sprintf("SELECT * FROM Missions WHERE MissionNumber='%s'",$id);
Raptor
  • 51,208
  • 43
  • 217
  • 353
Rumana
  • 1
  • 1
  • 1