Page 1 of 1

Always blank after the WHILE statement.

Posted: Mon Apr 10, 2006 4:42 pm
by Dale

Code: Select all

<?php
$conn = mysql_connect("localhost", "USERNAME", "PASSWORD");
mysql_select_db("DATATABLE", $conn) or die(mysql_error());

$sql = "SELECT * FROM customers WHERE cusid = '$_POST[cusid]' AND cusemail = '$_POST[cusemail]'";
$result = mysql_query($sql, $conn) or die(mysql_error());

while($custom = mysql_fetch_array($result)) {

echo "hello";

}
?>
Ok, above is my code (login.php), now for some reason when I try using this - even when I stick the correct details in (as they are in my database) anything after the

Code: Select all

while($custom = mysql_fetch_array($result)) {
is blank. The word "hello" is put there so I can see if it works, but nothing shows ... just a blank page. Any suggestions why??

Posted: Mon Apr 10, 2006 4:45 pm
by hawleyjr
Sounds like your query isn't returning anything. Have you echoed out your query?

Posted: Mon Apr 10, 2006 4:46 pm
by Dale
hawleyjr wrote:Sounds like your query isn't returning anything. Have you echoed out your query?
Just done that. It's still blank.

Posted: Mon Apr 10, 2006 4:48 pm
by hawleyjr
Well, if you had a connection or query error you should see a corresponding error message. Try to run the printed out query in your mysql admin panel. Just to see if it returns any results…

Posted: Mon Apr 10, 2006 4:49 pm
by Dale
hawleyjr wrote:Well, if you had a connection or query error you should see a corresponding error message. Try to run the printed out query in your mysql admin panel. Just to see if it returns any results…
Just moved the echo of my query and I get this
Resource id #3

Posted: Mon Apr 10, 2006 4:51 pm
by hawleyjr
Dale wrote:
hawleyjr wrote:Well, if you had a connection or query error you should see a corresponding error message. Try to run the printed out query in your mysql admin panel. Just to see if it returns any results…
Just moved the echo of my query and I get this
Resource id #3

You echoed your result variable not your $sql variable...

Code: Select all

<?php
$conn = mysql_connect("localhost", "USERNAME", "PASSWORD");
mysql_select_db("DATATABLE", $conn) or die(mysql_error());

$sql = "SELECT * FROM customers WHERE cusid = '$_POST[cusid]' AND cusemail = '$_POST[cusemail]'";

echo $sql;

$result = mysql_query($sql, $conn) or die(mysql_error());

while($custom = mysql_fetch_array($result)) {

echo "hello";

}
?>

Posted: Mon Apr 10, 2006 4:58 pm
by Dale
Ahh for some reason, now when I echo'd the SQL thingy it seems to show the "Hello". Hmmm... strange. Seems to work now.