Jump to content

Newby Help


tlebeau925

Recommended Posts

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

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/112990-newby-help/
Share on other sites

<?php
           if ($info['OkToSpam']=="on");
?>

 

Should be:

<?php
         if ($info['OkToSpam']=="on") //without ;
         {
            // if on -> do something
         }
         else
         {
             //do something else
         }
?>

 

--

jelly.

Link to comment
https://forums.phpfreaks.com/topic/112990-newby-help/#findComment-580410
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/112990-newby-help/#findComment-580416
Share on other sites

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.