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
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);
?>

Link to comment
Share on other sites

$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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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