I am building a database for a fan club, as I test the signup page I get these errors:

Can anyone help

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/rmilnerx/public_html/lilmaq/vSignup/process.php on line 50


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/rmilnerx/public_html/lilmaq/vSignup/process.php on line 61


Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/rmilnerx/public_html/lilmaq/vSignup/process.php on line 70


Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/rmilnerx/public_html/lilmaq/vSignup/process.php on line 73

Here is the code

<? require_once ("signupconfig.php"); ?>
<html>
<head>
<title>vSignup 2.5</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>


<body bgcolor="#FFFFFF" text="#000000">
<?
include ("auth.php");
$connection = mysql_connect($dbhost, $dbusername, $dbpassword);
$db = mysql_select_db($dbname);


// EDIT THIS IF YOU MODIFIED THE SIGNUP PAGE OR
// IF YOU ARE USING YOUR OWN SIGNUP FORM
// We  use the addslashes() function on some variables to prevent SQL Injection
$username = addslashes($_POST);
$password = $_POST;
$fname = $_POST;
$lname = $_POST;
$email = addslashes($_POST);
$country = $_POST;
$zipcode = $_POST;


// SIGNUP SETTINGS
$qSetup = mysql_query("SELECT * FROM signupsetup");
$SetupRow = mysql_fetch_array($qSetup);
$ValidEmailDomains = $SetupRow;
$profile = $SetupRow;
$defaultgroup = $SetupRow;
$defaultlevel = $SetupRow;
$AutoApprove = $SetupRow;
$AutoSend = $SetupRow;
$AutoSendAdmin = $SetupRow;


// EMAILER SETTINGS
$qEmailer = mysql_query("SELECT * FROM emailer WHERE profile='$profile'");
$EmailerRow = mysql_fetch_array($qEmailer);
$EmailerName = $EmailerRow["name"];
$EmailerFrom = $EmailerRow["email"];
$EmailerSubject = $EmailerRow["subject"];
$EmailerMessage = $EmailerRow["emailmessage"];


// SIGNUP FORM PROCESSING
$EmailQuery = mysql_query("SELECT * FROM signup WHERE email='$email'");
$email = strtolower($email);
$EmailExist = mysql_num_rows($EmailQuery);  // Returns 0 if not yet existing
$username = strtolower($username);
$UsernameQuery = mysql_query ("SELECT * FROM signup WHERE uname='$username'");
$UsernameExist = mysql_num_rows($UsernameQuery);


if (trim($ValidEmailDomains)=="")
{
$EmailArray = "";
}
else
{
$EmailArray = split (" ", $ValidEmailDomains);
}


// Generate confirmation key for settings which require one
$confirmkey =  md5(uniqid(rand()));


// CHECK FOR RESERVED USERNAMES
if (trim($username)=='sa' || trim($username)=='admin' || trim($username)=='test')
{
$UsernameExist = 1;
}


// CHECK FOR REQUIRED FIELDS
if (empty($username))
{
print "<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Username field cannot be left blank!</b></font></p>";
exit;
}
if (empty($password))
{
print "<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Password field cannot be left blank!</b></font></p>";
exit;
}
if (empty($fname))
{
print "<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>First Name field cannot be left blank!</b></font></p>";
exit;
}
if (empty($lname))
{
print "<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Last Name field cannot be left blank!</b></font></p>";
exit;
}
if (empty($email))
{
print "<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Email field cannot be left blank!</b></font></p>";
exit;
}


// Validate Email Address String
$good = ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
'@'.
'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',
$email);
if (!$good)
{
print "<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Email field has invalid characters!</b></font></p>";
exit;
}


// Validate Email Address String - FOR VALID EMAIL DOMAINS
$found=false;
if ($EmailArray!="")
{
for ($ct=0;$ct<=sizeof($EmailArray)-1;$ct++)
{
if (eregi($EmailArray[$ct], $email))
{
$ct=sizeof($EmailArray);
$found=true;
}
else
{
$found=false;
}
}
}
else
{
$found = true;
}
if (!$found)
{
print "<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Email address does not belong to the list of allowable email domains!</b></font></p>";
exit;
}


// Make sure username does not yet exist in the db
if ($UsernameExist>0)
{
print "<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Username already exists in the database!</b></font></p>";
exit;
}


// Make sure email address does not yet exist in the db
if ($EmailExist>0)
{
print "<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Email address already exists in the database!</b></font></p>";
exit;
}


// *********************************************************
// CHANGE THIS IF YOU WANT TO ADD FIELDS TO YOUR SIGNUP FORM
// *********************************************************
// Add new member to table signup
$addmember = mysql_query("INSERT INTO signup VALUES ('','$username','$fname','$lname','$email','$country','$zipcode',NOW(),'$confirmkey')");


// If SUCCESSFUL, add to vAuthenticate tables too
if ($addmember)
{
// Is the member auto-approved or not?
if ($AutoApprove==1)
{
$MemberStatus = "active";
}
else
{
$MemberStatus = "inactive";
}


$AddToAuth = new auth();
$add = $AddToAuth->add_user($username,$password,$defaultgroup,$defaultlevel,$MemberStatus,'', 0);
}


// Do we automatically send email notification to member or not?
if ($AutoSend == 1)
{
// if successful in adding to vAuthenticate, send confirmation email
if ($add==1)
{
// Replace all occurrences of the keys
// AVAILABLE KEYS: [[UNAME]], [[LNAME]], [[FNAME]], [[PASSWD]], [[EMAIL]], [[CONFIRM]]
$EmailerMessage = str_replace("[[UNAME]]", $username, $EmailerMessage);
$EmailerMessage = str_replace("[[PASSWD]]", $password, $EmailerMessage);
$EmailerMessage = str_replace("[[FNAME]]", $fname, $EmailerMessage);
$EmailerMessage = str_replace("[[LNAME]]", $lname, $EmailerMessage);
$EmailerMessage = str_replace("[[EMAIL]]", $email, $EmailerMessage);
$EmailerMessage = str_replace("[[CONFIRM]]", $confirm . '?confirmkey=' . $confirmkey, $EmailerMessage);


$sent = @mail($email, $EmailerSubject, $EmailerMessage, "From:$EmailerName<$EmailerFrom>\nReply-to:$EmailerFrom");
// $sent = @mail($email, $EmailerSubject, $EmailerMessage, "From:$EmailerName<$EmailerFrom>\nReply-to:$EmailerFrom\nContent-Type: text/html; charset=iso-8859-15");
}
}
// echo $EmailerMessage;    // DEBUGGER


// Do we automatically send notification message to the admin's email address (see signupconfig.php)?
if ($AutoSendAdmin == 1)
{
if ($add==1)
{
$AdminSubject = "New Membership Application!";
$AdminMessage = "This is to inform you that " . $username . " has applied for membership to our site.";
$sent = @mail($adminemail, $AdminSubject, $AdminMessage, "From:$EmailerName<$EmailerFrom>\nReply-to:$EmailerFrom");
}
}
?>


<p><font size="3" face="Verdana, Arial, Helvetica, sans-serif" color="#FF0000"><b>Thank
you for signing up!</b></font></p>


<?
if ($AutoSend == 1)
{
print "<p><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">";
print "A confirmation email was sent to the email address you specified. <br>";
print "Please confirm your membership as soon as you receive the email.";
print "</font></p>";
}
else
{
print "<p><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">";
print "Please click <a href=\"$RelLogin\">here</a> to go back to the login area";
print "</font></p>";
}
?>

Recommended Answers

All 7 Replies

Is all that code from process.php?

I imported it to an editor


line 50 = $UsernameExist = mysql_num_rows($UsernameQuery);

line 61 = // Generate confirmation key for settings which require one

line 70 = // CHECK FOR REQUIRED FIELDS

line 73 = print "<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Username field cannot be left blank!</b></font></p>";

so something isn't quite right. Could you post us line 50, 61, 70 and 73 from your code? That might make it easier to help.

Sam

Line 50 $SetupRow = mysql_fetch_array($qSetup);
Line 61 $EmailerRow = mysql_fetch_array($qEmailer);
Line 70 $EmailExist = mysql_num_rows($EmailQuery); // Returns 0 if not yet existing
Line 73 $UsernameExist = mysql_num_rows($UsernameQuery);

Thank you for your help!

Line 50 $SetupRow = mysql_fetch_array($qSetup);
Line 61 $EmailerRow = mysql_fetch_array($qEmailer);
Line 70 $EmailExist = mysql_num_rows($EmailQuery); // Returns 0 if not yet existing
Line 73 $UsernameExist = mysql_num_rows($UsernameQuery);

Thank you for your help!

It usually does gives that error if the datatype is different, say if you're searching for "hello" in a int field, it'll return that error.

Two ways to understand further:

1) change addslashes($_POST) to

mysql_real_escape_string($_POST['username'];

2) change your SQL to the following and add or die() -

$qSetup = mysql_query("SELECT * FROM `signupsetup`") or die("Error in qSetup: ".mysql_error()); // no where clause?

$qEmailer = mysql_query("SELECT * FROM `emailer` WHERE `profile`='$profile'") or die("Error in qEmailer: ".mysql_error());

$EmailExist = mysql_num_rows($EmailQuery) or die("Error in EmailExists: ".mysql_error()) ;	// Returns 0 if not yet existing
$UsernameExist = mysql_num_rows($UsernameQuery) or die("Error in UsernameExist: ".mysql_error());

see if that returns any specific errors?

Sam

I get this error:

Error in qSetup: No database selected

I get this error:

Error in qSetup: No database selected

There's something wrong with your connecting to the database then..

$connection = mysql_connect($dbhost, $dbusername, $dbpassword);
$db = mysql_select_db($dbname);

make sure you've spelt everything correctly in those variables, remember that SQL is case sensitive, as is php when it comes to variables. Make sure they're exactly the same there in process.php as they are in auth.php.

Sam

On the addslashes do I need to delete the whole line and paste the code you gave me into it?

On the addslashes do I need to delete the whole line and paste the code you gave me into it?

Yeah, replace

addslashes($_POST['username'];

with

mysql_real_escape_string($_POST['username'];

also to narrow down the problem further change the code at the top of your page to this:

$connection = mysql_connect($dbhost, $dbusername, $dbpassword) or die("Could not connect to database: ".mysql_error());
$db = mysql_select_db($dbname) or die("Could not select database: ".mysql_error());

Sam

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.