Forum Moderators: coopster

Message Too Old, No Replies

Strange error when enter non-standard email address in mysql

         

erikcw

6:59 pm on Jun 10, 2004 (gmt 0)

10+ Year Member



I'm getting the following error when I try to enter a non standard email into my database (this is for a user regisration page)

When I enter a more standard email name@domain.com, it works just fine. Any ideas?

NOTE: it should not be logging in as apache, all mysql user and password variables are defined at the top of the script.


Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/example/httpdocs/inc/auth.inc.php on line 181

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/example/httpdocs/inc/auth.inc.php on line 182

Warning: mysql_query(): Access denied for user: 'apache@localhost' (Using password: NO) in /home/httpd/vhosts/example/httpdocs/inc/auth.inc.php on line 193

Warning: mysql_query(): A link to the server could not be established in /home/httpd/vhosts/example/httpdocs/inc/auth.inc.php on line 193
Error in query: INSERT INTO `users` (`email`, `password`, `first`, `last`, `level`, `temp`, `receipt`, `timestamp`) VALUES ('them@example.com', '098f6bcd4621d373cade4e832627b4f6', 'erik', 'wickstrom', 'beta', 'test', '10026872', NOW()). Access denied for user: 'apache@localhost' (Using password: NO)


function new_user() {
extract($GLOBALS);
if ($_POST['signup']!= 2) {
?>
<form method="post" action="<? echo $_SERVER['PHP_SELF'];?>">
<table border="0" align="center">
<tr><td>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr><td><h4>Sign Up</h4></td></tr>
<tr>
<td align="right">First Name:</td>
<td>
<input type="text" name="first">
</td>
</tr>
<tr>
<td align="right">Last Name:</td>
<td>
<input type="text" name="last">
</td>
</tr>

<tr>
<td align="right">EMail:</td>
<td>
<input type="text" name="email">
</td>
</tr>
<tr>
<td align="right">Password:</td>
<td>
<input type="password" name="password">
</td>
</tr> <tr>
<td align="right">Confirm Password:</td>
<td>
<input type="password" name="password2">
</td>
</tr>
<tr align="center">
<td colspan="2"><input type="hidden" name="level" value="beta">
<input type="hidden" name="receipt" value="<? echo $cbreceipt;?>">
<input type="hidden" name="signup" value="2">
<input type="submit" name="register" value="Sign Up">
</td>
</tr>
</table>
</td></tr></table>
</form>
<?

} else {
//process signup

$first = $_POST['first'];
$last = $_POST['last'];
$email = $_POST['email'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$level = $_POST['level'];
$receipt = $_POST['receipt'];

// set up error list array
$errorList = array();
$count = 0;

// validate text input fields
if (!$first) { $errorList[$count] = "Invalid entry: First Name"; $count++; }

if (!$last) { $errorList[$count] = "Invalid entry: Last Name"; $count++; }

if (!$email OR validateEmail($email) == false) { $errorList[$count] = "Invalid entry: E-Mail"; $count++; }

if (!$password) { $errorList[$count] = "Invalid entry: Password"; $count++; }

if ($password!= $password2) { $errorList[$count] = "Invalid entry: Passwords do not Match"; $count++; }

// check for errors
// if none found...
if (sizeof($errorList) == 0)
{

// open database connection
$connection = mysql_connect($db_host, $db_user, $db_pass) or die ("Unable to connect!");

// select database
mysql_select_db($db_name) or die ("Unable to select database!");

//////////////////

$query = "SELECT `email` FROM users WHERE email='$email'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
}
// if existing user has been found, bounce error
if(mysql_num_rows($result) > 0) { $errorList[$count] = "Invalid entry: A user with this email address is already registrered with our system. Please click the back button to try again."; $count++; }
if(mysql_num_rows($result) == 0) {

////////////

$password = md5($password);
// generate and execute query

$query = "INSERT INTO `users` (`email`, `password`, `first`, `last`, `level`, `temp`, `receipt`, `timestamp`) VALUES ('$email', '$password', '$first', '$last', '$level', '$password2', '$receipt', NOW())";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

// print result
echo "<tr><td><h3>Registration Successful.</h3></td></tr><tr><td>";
echo "<a href='index.php'>Click Here to Login for the First Time</a>"; //login();

// close database connection
mysql_close($connection);

}
else
{
// errors found
// print as list
echo "<font size=-1>The following errors were encountered: <br>";
echo "<ul>";
for ($x=0; $x<sizeof($errorList); $x++)
{
echo "<li>$errorList[$x]";
}
echo "</ul></font>";
}
}
}

[edited by: jatar_k at 4:53 am (utc) on June 11, 2004]
[edit reason] generalized [/edit]

coopster

7:15 pm on Jun 10, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I would venture to guess that an invalid email is causing your error count to be greater than zero, therefore you never make the connection to the database and are receiving the associated errors.
... 
if (!$email OR validateEmail($email) == false) {
$errorList[$count] = "Invalid entry: E-Mail"; $count++;
}
...
if (sizeof($errorList) == 0) {
// open database connection
$connection = mysql_connect($db_host, $db_user, $db_pass)
or die ("Unable to connect!");
// select database
mysql_select_db($db_name) or die ("Unable to select database!");
$query = "SELECT `email` FROM users WHERE email='$email'";
$result = mysql_query($query)
or die ("Error in query: $query. " . mysql_error());
}

erikcw

8:26 pm on Jun 10, 2004 (gmt 0)

10+ Year Member



That did it! Can't believe I missed it!