npsari Posted April 9, 2007 Share Posted April 9, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/46281-solved-a-simple-question-yet-hard-for-me/ Share on other sites More sharing options...
clown[NOR] Posted April 9, 2007 Share Posted April 9, 2007 try changing if ($Location='') { to if ($Location == '') { Quote Link to comment https://forums.phpfreaks.com/topic/46281-solved-a-simple-question-yet-hard-for-me/#findComment-225149 Share on other sites More sharing options...
trq Posted April 9, 2007 Share Posted April 9, 2007 <?php if (!isset($Location) || empty($Location)) { print "No location"; } else { print "Location available"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/46281-solved-a-simple-question-yet-hard-for-me/#findComment-225151 Share on other sites More sharing options...
clown[NOR] Posted April 9, 2007 Share Posted April 9, 2007 or you can use that Quote Link to comment https://forums.phpfreaks.com/topic/46281-solved-a-simple-question-yet-hard-for-me/#findComment-225155 Share on other sites More sharing options...
npsari Posted April 9, 2007 Author Share Posted April 9, 2007 Ok, thanks, i will try them both now Quote Link to comment https://forums.phpfreaks.com/topic/46281-solved-a-simple-question-yet-hard-for-me/#findComment-225157 Share on other sites More sharing options...
npsari Posted April 9, 2007 Author Share Posted April 9, 2007 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/46281-solved-a-simple-question-yet-hard-for-me/#findComment-225160 Share on other sites More sharing options...
sasa Posted April 9, 2007 Share Posted April 9, 2007 add line $Location = "row['Location']; before if and after while Quote Link to comment https://forums.phpfreaks.com/topic/46281-solved-a-simple-question-yet-hard-for-me/#findComment-225177 Share on other sites More sharing options...
boo_lolly Posted April 9, 2007 Share Posted April 9, 2007 where is location being set? as in where is this line: $Location = ????????? Quote Link to comment https://forums.phpfreaks.com/topic/46281-solved-a-simple-question-yet-hard-for-me/#findComment-225180 Share on other sites More sharing options...
npsari Posted April 9, 2007 Author Share Posted April 9, 2007 SaSa.. Can you show me how plz paste the code with your part ... if you can I am a noobie afterall Quote Link to comment https://forums.phpfreaks.com/topic/46281-solved-a-simple-question-yet-hard-for-me/#findComment-225182 Share on other sites More sharing options...
npsari Posted April 9, 2007 Author Share Posted April 9, 2007 where is location being set? as in where is this line: $Location = ????????? boo I dont understand what you mean Can you explain please your question Quote Link to comment https://forums.phpfreaks.com/topic/46281-solved-a-simple-question-yet-hard-for-me/#findComment-225186 Share on other sites More sharing options...
sasa Posted April 9, 2007 Share Posted April 9, 2007 $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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/46281-solved-a-simple-question-yet-hard-for-me/#findComment-225192 Share on other sites More sharing options...
npsari Posted April 9, 2007 Author Share Posted April 9, 2007 DONE GUYS THAKS Quote Link to comment https://forums.phpfreaks.com/topic/46281-solved-a-simple-question-yet-hard-for-me/#findComment-225199 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.