Jump to content

error unable to resolve


narjis

Recommended Posts

In the given code below I am getting this error

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\samples\getcustomers.php on line 20

WHY?

 

 

<?php
$value = $_GET["q"];
  $con = mysql_connect('localhost', 'root', ''); 
  //db_connect();
  if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  $db_selected = mysql_select_db("ajaxDb",$con);
  $sql = "SELECT * FROM 'cutomers' WHERE Name = '".$value."'";
// echo $sql;
$result = mysql_query($sql);
  echo "<table border='1'>
<tr>
<th>Name</th>
<th>Address</th>
<th>Country</th>
</tr>";
        
  while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['Name'] . "</td>";
  echo "<td>" . $row['Address'] . "</td>";
  echo "<td>" . $row['Country'] . "</td>";
  echo "</tr>";
  }
  echo "</table>";
  mysql_close($con);
?>

Link to comment
Share on other sites

For whatever reason, your query is failing and returning a boolean FALSE as a result. Are you sure your connection and db selection are actually successful? You don't have any logic in place to make sure those 2 operations succeed before allowing the query to run.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.