i am trying to run this code but i am not getting anything from the mysql_fetch_assoc($result)
it is just blank can anyone help me
thanks in advance

<html>
<body>
<?php

$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="hayden"; // Mysql password 
$db_name="ecng3020"; // Database name 
$tbl_name="students"; // Table name
$tbl_name_1="staff"; // Table name

$sql="SELECT * FROM $tbl_name WHERE id_no='$username' and password='$password='";

if (mysql_connect("$host","$username","$password"))
	echo "<p>connected to mysql</p>";
else
	echo "<p>could not connect</p>";

if (mysql_select_db("$db_name"))
	echo "<p>selected db</p>";
else
	echo "<p>could not select db</p>";
	


if ($result = mysql_query($sql))
	echo "<p>success</p>";
else
	echo "<p>fail</p>";

while ($row = mysql_fetch_assoc($result))
{
	echo "<p>$row[0] $row[1] $row[2] $row[3] $row[4] $row[5]";
}


?>
</body>
</html>

Looks like you probably have an extra = after password

try this

$sql="SELECT * FROM $tbl_name WHERE id_no='$username' and password='$password'";

well i haven't really tried using mysql_fetch_assoc(), coz. i prefer mysql_fetch_array(). but from what i know about mysql_fetch_assoc() it returns associative arrays of your recordset. So your array index and values are dependent on your recordset. try print_r() to see the array values.

oh yeah... i think you got syntax error

$sql="SELECT * FROM $tbl_name WHERE id_no='$username' and password='$password='";

you put = after the password, it may be the result why you got no results coz. the query doesn't satisfy the condition.

seriously vaultdweller123, you are copying all of my posts and reposting them. stop.

what? copying you? u got the nerve to say that? why should i copy you what to i get from that? im here to help and learn. Your too full of yourself! if i would copy someone, i would select a more smarter person rather than you. i would prever copy ardav over to you. >:(

what? copying you? u got the nerve to say that? why should i copy you what to i get from that? im here to help and learn. Your too full of yourself! if i would copy someone, i would select a more smarter person rather than you. i would prever copy ardav over to you. >:(

wow. grow up. and stop copying my posts

You would probably check your sql statement and one more thing you should get the retrieved data with this way:

while ($row = mysql_fetch_assoc($result)) {
    echo $row["userid"];
    echo $row["fullname"];
    echo $row["userstatus"];
}

instead of

while ($row = mysql_fetch_assoc($result)) {
    echo $row[0];
    echo $row[1];
    echo $row[2];
}

click here for more information: mysql_fetch_assoc()

wow. grow up. and stop copying my posts

sorry but i don't copy on dumb person... ur just a feeler... ahaha