narjis Posted April 7, 2011 Share Posted April 7, 2011 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/233025-error-unable-to-resolve/ Share on other sites More sharing options...
Pikachu2000 Posted April 8, 2011 Share Posted April 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233025-error-unable-to-resolve/#findComment-1198494 Share on other sites More sharing options...
spiderwell Posted April 8, 2011 Share Posted April 8, 2011 customers is typoed? Quote Link to comment https://forums.phpfreaks.com/topic/233025-error-unable-to-resolve/#findComment-1198498 Share on other sites More sharing options...
PFMaBiSmAd Posted April 8, 2011 Share Posted April 8, 2011 Your table name is enclosed in single-quotes, thereby making it a piece of string data, rather than a table name. Quote Link to comment https://forums.phpfreaks.com/topic/233025-error-unable-to-resolve/#findComment-1198503 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.