Forum Moderators: coopster

Message Too Old, No Replies

If / Else help?

         

adammc

1:22 am on Sep 11, 2005 (gmt 0)

10+ Year Member



Hi,

I am having trouble constructing this if / else code.
If the user doesnt enter an email addie it prints "oops, you forgot...." But it still registers the user even though there was a problem?

If the username already exists the code works and it doesn't register the visior


if (empty ($job_seeker_email))
{
Print "<br><br><font font size='2' face='Verdana' color='#000099'><b>Oops</b></font><font font size='2' face='Verdana' color='black'>, you forgot to fill in your email address.<br> Please go back and try again.</font>";
}

$result=mysql_query("SELECT * FROM job_seeker_info WHERE uname='$uname'");
if (mysql_num_rows($result) >=1)
{

Print "<br><br><font font size='2' face='Verdana' color='#000099'><b>Sorry </b></font><font font size='2' face='Verdana' color='black'>, that username is taken.<br> Please go back and try again.</font>";

}
else
{

$query = "insert into job_seeker_info set

angryBinary

3:53 am on Sep 11, 2005 (gmt 0)

10+ Year Member



If i'm not mistaken, you want to NOT register the user if he/she/it doesn't supply email. In order to skip the 'registration' bit of code, you can enclose it in an 'else' clause. Just hug it with some brackets:

if (empty ($job_seeker_email))
{
Print "<br><br><font font size='2' face='Verdana' color='#000099'><b>Oops</b></font><font font size='2' face='Verdana' color='black'>, you forgot to fill in your email address.<br> Please go back and try again.</font>";
} else {
$result=mysql_query("SELECT * FROM job_seeker_info WHERE uname='$uname'");
if (mysql_num_rows($result) >=1)
{

Print "<br><br><font font size='2' face='Verdana' color='#000099'><b>Sorry </b></font><font font size='2' face='Verdana' color='black'>, that username is taken.<br> Please go back and try again.</font>";

}
else
{

$query = "insert into job_seeker_info set... etc etc

}
}

adammc

4:40 am on Sep 11, 2005 (gmt 0)

10+ Year Member



angryBinary, thanks for the reply.

If I wanted to add more error checking code to check if the user filled his first name, address e.tc

How would I construct the is / else?

dkin

6:00 am on Sep 11, 2005 (gmt 0)

10+ Year Member



It looks to me like the code provided should work for you, if not please be a little more descriptive in your problem maybe I can help further.

adammc

6:27 am on Sep 11, 2005 (gmt 0)

10+ Year Member



I was hoping to add code to check other fields on the form. Is the code below in the right format in regards to the if else statements and correct usage of the curly brackets?

I dont want the scrip tto enter the data into the database until everything above has been verified.


if (empty ($job_seeker_email))
{
Print "<br><br><font font size='2' face='Verdana' color='#000099'><b>Oops</b></font><font font size='2' face='Verdana' color='black'>, you forgot to fill in your email address.<br> Please go back and try again.</font>";
}

if (empty ($first_name))
{
Print "<br><br><font font size='2' face='Verdana' color='#000099'><b>Oops</b></font><font font size='2' face='Verdana' color='black'>, you forgot to fill in your first name.<br> Please go back and try again.</font>";
}

if (empty ($last_name))
{
Print "<br><br><font font size='2' face='Verdana' color='#000099'><b>Oops</b></font><font font size='2' face='Verdana' color='black'>, you forgot to fill in your email address.<br> Please go back and try again.</font>";
}

$result=mysql_query("SELECT * FROM job_seeker_info WHERE uname='$uname'");
if (mysql_num_rows($result) >=1)
{

Print "<br><br><font font size='2' face='Verdana' color='#000099'><b>Sorry </b></font><font font size='2' face='Verdana' color='black'>, that username is taken.<br> Please go back and try again.</font>";

}

else
{

$query = "insert into job_seeker_info set... etc etc

}

dkin

8:34 am on Sep 11, 2005 (gmt 0)

10+ Year Member



this should perform they way your wanting it to, everything looks to be in order, try it and let me know

if (empty ($job_seeker_email))
{
Print "<br><br><font font size='2' face='Verdana' color='#000099'><b>Oops</b></font><font font size='2' face='Verdana' color='black'>, you forgot to fill in your email address.<br> Please go back and try again.</font>";
exit;
}

if (empty ($first_name))
{
Print "<br><br><font font size='2' face='Verdana' color='#000099'><b>Oops</b></font><font font size='2' face='Verdana' color='black'>, you forgot to fill in your first name.<br> Please go back and try again.</font>";
exit;
}

if (empty ($last_name))
{
Print "<br><br><font font size='2' face='Verdana' color='#000099'><b>Oops</b></font><font font size='2' face='Verdana' color='black'>, you forgot to fill in your email address.<br> Please go back and try again.</font>";
exit;
}

$result=mysql_query("SELECT * FROM job_seeker_info WHERE uname='$uname'");
if (mysql_num_rows($result) >=1)
{

Print "<br><br><font font size='2' face='Verdana' color='#000099'><b>Sorry </b></font><font font size='2' face='Verdana' color='black'>, that username is taken.<br> Please go back and try again.</font>";

}

else
{

$query = "insert into job_seeker_info set... etc etc

}

adammc

11:23 pm on Sep 11, 2005 (gmt 0)

10+ Year Member



dkin,
THANK YOU SOOOOO MUCH!

It works a treat :)

dkin

12:39 am on Sep 12, 2005 (gmt 0)

10+ Year Member



np, glad I could help.