Jump to content

Warning: Mysql_Fetch_Assoc() Expects Parameter 1 To Be Resource, Boolean


Recommended Posts

You have an error with your mysql query. I would need your query to determine if it is your query or your database.

 

The other option is you can run the following code after adding your info:

<?php

// Edit below this line

$mysql_host="localhost";
$mysql_user="username";
$mysql_pass="password";
$mysql_database="database"
$mysql_sql="SELECT id as userid, fullname, userstatus FROM sometable WHERE  userstatus = 1";

// Do NOT Edit below this line

$conn = mysql_connect($mysql_host, $mysql_user, $mysql_pass);

if (!$conn) {
   echo "Unable to connect to DB: " . mysql_error();
   exit;
}

if (!mysql_select_db($mysql_database)) {
   echo "Unable to select " . $mysql_database . ": " . mysql_error();
   exit;
}

$result = mysql_query($mysql_sql);

if (!$result) {
   echo "Could not successfully run query ($mysql_sql) from DB: " . mysql_error();
   exit;
}

if (mysql_num_rows($result) == 0) {
   echo "No rows found, nothing to print so I am exiting";
   exit;
}

while ($row = mysql_fetch_assoc($result)) {
   echo $row . "</br>";
}

mysql_free_result($result);

?>

Edited by unlishema.wolf

my coding was

<?php

mysql_connect("localhost","root","");

mysql_select_db("mydb");

$query="seleect * from table5";

$result=mysql_query($query);

?>

<table><tr><td>name</td><td>age</td><td>gender

</td><td>language1</td><td>language2</td><td>country

</td><td>address</td><td>edit</td><td>delete</td></tr>

<?php

while($row=mysql_fetch_assoc($result))

{

?>

<tr>

<td><?php echo($row['name']); ?></td>

<td><?php echo($row['age']); ?></td>

<td><?php echo($row['gender']); ?></td>

<td><?php echo($row['language1']); ?></td>

<td><?php echo($row['language2']); ?></td>

<td><?php echo($row['country']); ?></td>

<td><?php echo($row['myaddress']); ?></td>

<td><a href=edit.php?id=<?php echo($row['id']); ?>

?>>edit</a></td>

<td><a href=delete.php?id=<?php echo($row['id']);

?>></a></td>

<?php

}

?>

</table>

Looking at the query you have spelt 'SELECT' like 'SELEECT.

 

If you change it to 'SELECT' it should work, I can't see anything else on first glance which could be causing it.

 

Kind regards,

 

AoTb.

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.