Forum Moderators: coopster

Message Too Old, No Replies

script not working

         

paul161

4:18 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



I wrote the script below it works fine put what I want it to do is, IF their is no value to variable $name to echo (No Name) at the moment is leaves it blank.
Any Ideas how this could be done?

$dbhost = "localhost";
$dbname = "######";
$dbuser = "######";
$dbpass = "#####";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());


$result="select * from login where username='$username'";
$result=mysql_query($result) or die(mysql_error());
$result=mysql_fetch_array($result);
?>
<?php echo $result[name];?>

Receptional Andy

4:52 pm on Nov 15, 2005 (gmt 0)



That's easy enough Paul! You could use something like

<?php if ($result[name]) {echo $result[name];} else {echo "No Name";}?>

if ($variable) wil check if the variable is set.

paul161

6:33 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



Thanks