Always blank after the WHILE statement.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Always blank after the WHILE statement.

Post 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??
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Sounds like your query isn't returning anything. Have you echoed out your query?
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post 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.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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…
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post 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
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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";

}
?>
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post 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.
Post Reply