Jump to content

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

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.