Another problem with MySQL - simple registration form gives blank screen, no errors
Okay, believe me I have been sitting here for a long time staring at this. I can't for the life of me figure out what is wrong.
I get no error message even with them turned on. When I take away the die statements it displays the text at the end so it's definitely an SQL error. Gah I hate SQL!
<?php
include('functions.php');
if(!$_POST['regtype'] || !$_POST['regemail'] || !$_POST['regpass'] || !$_POST['regpass2']) {
"You didn't fill out a required field.";
exit();
}
if($_POST['regpass'] != $_POST['regpass2']) {
"Your passwords didn't match.";
exit();
}
$regtype = protect($_POST['regtype']);
$regemail = protect($_POST['regemail']);
$regpass = protect($_POST['regpass']);
$secregpass = sha1($regpass);
$regdate = date("Y/m/d");
// seems to be right below here
$checksql = "SELECT * FROM profile WHERE email = '$regemail'";
$checkquery = mysql_query($checksql,$connect) or die(mysql_error());
$checknumrows = mysql_num_rows($checkquery) or die(mysql_error());
if($checknumrows > 0) {
"A user with that email already exists!";
exit();
} else {
$inssql = "INSERT INTO profile (email, pass, type, regdate) VALUES ('$regemail', '$secregpass', '$regtype','$regdate')";
$insquery = mysql_query($inssql, $connect) or die(mysql_error());
//these are just some of my notes
//need to make confirmation mail script later - or use donation verification as everything. def need to set up mail server
$_SESSION['email'] = $regemail;
echo "You have successfully registered.
<br /><br />
You're almost done! Please pick the charity you would like to donate to, and how much you would like to donate (minimum of $25).
<br /><br />
If you can't decide, you can donate to our general fund, which is equitably distributed to each charity (and is not handled by us!).
<br /><br />
<form action='donate.php' method='get'>
Charity:
<br />开发者_JS百科;<br />
<select>
<option name='charity' value='1'>Charity 1</option>
<option name='charity' value='2'>Charity 2</option>
<option name='charity' value='3'>Charity 3</option>
</select>
<br /><br />
USD: $<input type='text' name='amount' />
";
}
?>
By the way, here's the 'protect' function:
function protect($string){
$string = trim(strip_tags(addslashes($string)));
return $string;
}
brad, this was probably the problem;
$checknumrows = mysql_num_rows($checkquery) or die(mysql_error());
if profile doesn't contain the given email, mysql_num_rows($checkquery)
will be 0 so it executes die(mysql_error())
but there's no error so the die() doesn't print anything. In short, get rid of or die(mysql_error())
精彩评论