[SOLVED] very basic if/else problems
Posted: Mon Apr 04, 2005 10:25 am
I'm missing something so basic, but I can't figure it out. I think I need sleep. Basically, I'm adding a player to a database, and if the email address entered (via html form) already exists in the database, the code prints the message 'the player already exists.' However if the email address doesn't exist, it adds the player's info to the database. The code can find the duplicate email fine and puts out the alert message, but if it is a new email address, it won't run the code to after the else statement. I know there is probably a million other ways to do this more efficiently, but I stink at php. Thanks in advance.
code:
code:
Code: Select all
<?PHP
$email = $_REQUEST['email'] ;
$hd = mysql_connect("host", "username", "password")
or die ("Unable to connect");
$result = mysql_select_db ("databasename", $hd)
or die ("Unable to select database");
$getoldemail = mysql_query("SELECT * FROM table_1 WHERE email='$email'")
or die(mysql_error());
$oldemail = mysql_fetch_array( $getoldemail )
or die(mysql_error());
$oldemailarray = $oldemail['email'] ;
if ($oldemailarray == $email) {
echo "<p class='style1'>ERROR:</p> Player already entered.<br><br>";
echo "<a href='javascript:history.back(1);'>Back</a>";
mysql_close($hd);
}
else {
$sql = "SELECT * FROM table_2 WHERE email='$email'";
$result = mysql_query($sql) or die ("Couldn't get reults.");
$count = mysql_num_rows($result);
if ($count == 1 ) {
my code
mysql_close($hd);
}
else if ($count == 0) {
my code
mysql_close($hd);
}
}
?>