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 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 == '') { 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"; } ?> 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 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 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); ?> 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 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 = ????????? 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 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 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); ?> 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 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
Archived
This topic is now archived and is closed to further replies.