Jump to content

[SOLVED] empty mysql gives error


ronnie88

Recommended Posts

I'm sure this has been answered before but couldn't find it Its giving me an error  if the mysql field is empty

im using it for this script...

 

<?
$query  = "SELECT va, cash FROM users WHERE username='{$_SESSION['username']}'";
$result = mysql_query($query);

while($row = mysql_fetch_assoc($result))
{
    echo "{$row['va']} <br>" .
         "Cash : {$row['cash']} <br>" .
         "Flight's Available : {$row['flights']} <br>";
?>

 

Any Help would be appreciated!

Link to comment
https://forums.phpfreaks.com/topic/116142-solved-empty-mysql-gives-error/
Share on other sites

try changing it to this and see what happens...

<?php
if(isset($_SESSION['username']) && !empty($_SESSION['username'])) {
$query  = "SELECT va, cash FROM users WHERE username='{$_SESSION['username']}'";
$result = mysql_query($query) or die("There was a Error: ".mysql_error());

while($row = mysql_fetch_assoc($result))
{
   echo "{$row['va']} <br>" .
        "Cash : {$row['cash']} <br>" .
        "Flight's Available : {$row['flights']} <br>";
}

} else { echo "Username is not set!"; }

?>

 

Regards ACE

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.