tlebeau925 Posted July 2, 2008 Share Posted July 2, 2008 I have a form I generated with PHPform that I have set to enter the results into a SQL database. I want to display the email address of the people that check the "OkToSpam" box Im a newb at PHP and in my mind this should work... but it dont: <?php mysql_connect("localhost", "******", "******") or die(mysql_error()); mysql_select_db("dslforms") or die(mysql_error()); $data = mysql_query("SELECT * FROM dslprospect") or die(mysql_error()); Print "<b>Coma Separated List:</b><br>"; while($info = mysql_fetch_array( $data )) { if ($info['OkToSpam']=="on"); Print " ".$info['Email'] . ", "; else echo "<br>"; } ?> And yes I have the tables created and they can be accessed easily outside of the "if" part Quote Link to comment https://forums.phpfreaks.com/topic/112990-newby-help/ Share on other sites More sharing options...
lemmin Posted July 2, 2008 Share Posted July 2, 2008 Looks ok to me. Maybe try print_r($info) at the beginning of the while loop to see if there are actually any rows that have the right criteria. Quote Link to comment https://forums.phpfreaks.com/topic/112990-newby-help/#findComment-580406 Share on other sites More sharing options...
jelly Posted July 2, 2008 Share Posted July 2, 2008 <?php if ($info['OkToSpam']=="on"); ?> Should be: <?php if ($info['OkToSpam']=="on") //without ; { // if on -> do something } else { //do something else } ?> -- jelly. Quote Link to comment https://forums.phpfreaks.com/topic/112990-newby-help/#findComment-580410 Share on other sites More sharing options...
lemmin Posted July 2, 2008 Share Posted July 2, 2008 You only need curly braces if you have more than one line (semi-colon) of code to be executed as a result of the condition; however, you are right that the semi-colon should not be there. The semi-colon should throw an error, though, so that must be what he meant by "it don't [work]." I figured he meant it was just displaying the else condition. Quote Link to comment https://forums.phpfreaks.com/topic/112990-newby-help/#findComment-580416 Share on other sites More sharing options...
jelly Posted July 2, 2008 Share Posted July 2, 2008 @lemmin Yes, I know, but with {,} just looks more 'clear'. (-; -- jelly. Quote Link to comment https://forums.phpfreaks.com/topic/112990-newby-help/#findComment-580418 Share on other sites More sharing options...
tlebeau925 Posted July 2, 2008 Author Share Posted July 2, 2008 Thanks, that worked perfectly! PHP is so complex >< Quote Link to comment https://forums.phpfreaks.com/topic/112990-newby-help/#findComment-580422 Share on other sites More sharing options...
revraz Posted July 2, 2008 Share Posted July 2, 2008 He probably isn't showing errors and gets a blank screen. Quote Link to comment https://forums.phpfreaks.com/topic/112990-newby-help/#findComment-580425 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.