Jump to content

[SOLVED] A simple question... yet hard for me :(


npsari

Recommended Posts

if ($Location='') {
     print "No location";
} else {
     print "Location available";
}

 

 

Some users leave the Location-field empty (when submiting their details)

 

Therefore, no Location is saved in the database

 

So, I did the above code which shows if Location is empty or not

 

But it always gives me 'Location available'  :-[

 

Is there any way to do it

Link to comment
https://forums.phpfreaks.com/topic/46281-solved-a-simple-question-yet-hard-for-me/
Share on other sites

I tried both, they dont work :(

 

Is it a problem that the field type is VARCHAR ?

 

This is the whole code Iam using too

 

<?php
$con = mysql_connect("localhost","name","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("database", $con);

$result = mysql_query("SELECT * FROM users");

while($row = mysql_fetch_array($result))
  {
  echo $row['Title']; print"<br><br>\n";


  if (!isset($Location) || empty($Location)) {
     print "No location...";
  } else {
     print "Location available";
  }

  
}

mysql_close($con);
?>

$result = mysql_query("SELECT * FROM users");

while($row = mysql_fetch_array($result))
  {
  echo $row['Title']; print"<br><br>\n";

$Location = $row['Location']; // or the your name for location in db

  if (!isset($Location) || empty($Location)) {
     print "No location...";
  } else {
     print "Location available";
  }

  
}

mysql_close($con);
?>

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.