Newb help !! (so close) ....
Posted: Fri Sep 11, 2009 6:19 pm
Hi all,
I'm trying to register members to a DB called myMembers with a script I've (very lightly) modified
from a tutorial. The only changes I've made are to take out a few feilds from the form.
When I hit "Submit" I get just two errors and I'm too much of a newb to understand how to correct them.
I've done pretty well on my own so far but now turn to you good people for help !
Errors are:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Sites/com/shutterbugclub/www/register.php on line 54
No database selected
All and any help on this very much appreciated.
Best wishes
Monty
Code I'm using is below. On line 50 you'll see "scripts/connect_to_mysql.php" and I know the script there works because I've tested it
separately - but I'll happily post it if it might help.
I'm trying to register members to a DB called myMembers with a script I've (very lightly) modified
from a tutorial. The only changes I've made are to take out a few feilds from the form.
When I hit "Submit" I get just two errors and I'm too much of a newb to understand how to correct them.
I've done pretty well on my own so far but now turn to you good people for help !
Errors are:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Sites/com/shutterbugclub/www/register.php on line 54
No database selected
All and any help on this very much appreciated.
Best wishes
Monty
Code I'm using is below. On line 50 you'll see "scripts/connect_to_mysql.php" and I know the script there works because I've tested it
separately - but I'll happily post it if it might help.
Code: Select all
<?php
// Created BY Adam Khoury @ http://www.developphp.com
// let's initialize vars to be printed to page in the HTML section so our script does not return errors
// they must be initialized in some server environments
$errorMsg = "";
$firstname = "";
$lastname = "";
$website = "";
$youtube = "";
$email = "";
$pass = "";
// This code runs only if the form submit button is pressed
if (isset ($_POST['firstname'])){
/* Example of cleaning variables in a loop
$vars = "";
foreach ($_POST as $key => $value) {
$value = stripslashes($value);
$vars .= "$key = $value<br />";
}
print "$vars";
exit();
*/
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$website = $_POST['website'];
$youtube = $_POST['youtube'];
$email = $_POST['email'];
$pass = $_POST['pass'];
$humancheck = $_POST['humancheck'];
$firstname = stripslashes($firstname);
$lastname = stripslashes($lastname);
$website = stripslashes($website);
$youtube = stripslashes($youtube);
$email = stripslashes($email);
$pass = stripslashes($pass);
$firstname = strip_tags($firstname);
$lastname = strip_tags($lastname);
$website = strip_tags($website);
$youtube = strip_tags($youtube);
$email = strip_tags($email);
$pass = strip_tags($pass);
// Connect to database
include_once "scripts/connect_to_mysql.php";
$emailCHecker = mysql_real_escape_string($email);
$emailCHecker = eregi_replace("`", "", $emailCHecker);
// Database duplicate e-mail check setup for use below in the error handling if else conditionals
$sql_email_check = mysql_query("SELECT email FROM myMembers WHERE email='$emailCHecker'");
$sql_email_check = mysql_num_rows($sql_email_check);
// Error handling for missing data
if ((!$firstname) || (!$lastname) || (!$email) || (!$pass)) {
$errorMsg = 'ERROR: You did not submit the following required information:<br /><br />';
if(!$firstname){
$errorMsg .= ' * First Name<br />';
}
if(!$lastname){
$errorMsg .= ' * Last Name<br />';
}
if(!$email){
$errorMsg .= ' * Email Address<br />';
}
if(!$pass){
$errorMsg .= ' * Login Password<br />';
}
} else if ($humancheck != "") {
$errorMsg = 'ERROR: The Human Check field must be cleared to be sure you are human<br />';
} else if ($sql_email_check > 0){
$errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our database. Please use another.<br />";
} else { // Error handling is ended, process the data and add member to database
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$firstname = mysql_real_escape_string($firstname);
$lastname = mysql_real_escape_string($lastname);
$website = mysql_real_escape_string($website);
$youtube = mysql_real_escape_string($youtube);
$email1 = mysql_real_escape_string($email);
$pass1 = mysql_real_escape_string($pass);
$firstname = eregi_replace("`", "", $firstname);
$lastname = eregi_replace("`", "", $lastname);
$website = eregi_replace("`", "", $website);
$youtube = eregi_replace("`", "", $youtube);
$email1 = eregi_replace("`", "", $email);
$pass1 = eregi_replace("`", "", $pass);
$website = eregi_replace("http://", "", $website);
$youtube = eregi_replace("http://www.youtube.com/user/", "", $youtube);
// Add MD5 Hash to the password variable
$db_password = md5($pass);
// Add user info into the database table for the main site table(audiopeeps.com)
$sql = mysql_query("INSERT INTO myMembers (firstname, lastname, email, password, sign_up_date, website, youtube)
VALUES('$firstname','$lastname','$email','$db_password', now(),'$website','$youtube')")
or die (mysql_error());
$id = mysql_insert_id();
// Create directory(folder) to hold each user's files(pics, MP3s, etc.)
mkdir("members/$id", 0755);
//!!!!!!!!!!!!!!!!!!!!!!!!! Email User the activation link !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$to = "$email1";
$from = "admin@shutterbugclub.com";
$subject = "Complete yourdomain registration";
//Begin HTML Email Message
$message = "Hi $firstname,
Complete this step to activate your login identity at ShutterBugClub.com.
Click the line below to activate when ready.
http://www.yourdomain.com/activation.ph ... b_password
If the URL above is not an active link, please copy and paste it into your browser address bar
Login after successful activation using your:
E-mail Address: $email1
Password: $pass1
See you on the site!
you@shutterbugclub.com";
//end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text\r\n";
mail($to, $subject, $message, $headers);
$msgToUser = "<h2>One Last Step - Activate through Email</h2><h4>OK $firstname, one last step to verify your email identity:</h4><br />
In a moment you will be sent an Activation link to your email address.<br /><br />
<br />
<strong><font color=\"#990000\">VERY IMPORTANT:</font></strong>
If you check your email with your host providers default email application, there may be issues with seeing the email contents. If this happens to you and you cannot read the message to activate, download the file and open using a text editor. If you still cannot see the activation link, contact site admin and briefly discuss the issue.<br /><br />
";
include_once 'msgToUser.php';
exit();
} // Close else after duplication checks
} else { // if the form is not posted with variables, place default empty variables
$errorMsg = "Fields marked with an [ * ] are required";
$firstname = "";
$lastname = "";
$website = "";
$youtube = "";
$email1 = "";
$pass1 = "";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Description" content="Register to Shutterbugclub" />
<meta name="Keywords" content="register, yourdomain" />
<meta name="rating" content="General" />
<title>Register Your Shutterbugclub Account</title>
<link href="styles/main.css" rel="stylesheet" type="text/css" />
<link rel="icon" href="http://www.shutterbugclub.com/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="http://www.shutterbugclub.com/favicon.ico" type="image/x-icon" />
<style type="text/css">
<!--
.brightRed {
color: #F00;
}
.textSize_9px {
font-size: 9px;
}
-->
</style>
</head>
<body>
<?php include_once "header_template.php"; ?>
<table width="950" align="center">
<tr>
<td width="758">
<blockquote>
<h2><br />
Create Your Account </h2>
</blockquote>
<table width="651" align="center" cellpadding="5">
<form action="register.php" method="post" enctype="multipart/form-data">
<tr>
<td width="125" class="style7"><div align="center" class="blueText">Please
Do First →</div></td>
<td width="498" bgcolor="#FFFFFF">Add <a href="mailto:admin@shutterbugclub.com"><u>admin@shutterbugclub.com</u></a>
to your email white list or safe sender list now, or else you might
not get the activation email that is necessary for logging in successfully.
</td>
</tr>
<tr>
<td colspan="2"><font color="#FF0000"><?php print "$errorMsg"; ?></font></td>
</tr>
<tr>
<td align="right" class="alignRt">First Name:<span class="brightRed">
*</span></td>
<td><input name="firstname" type="text" class="formFields" id="firstname" value="<?php print "$firstname"; ?>" size="32" maxlength="20" /></td>
</tr>
<tr>
<td align="right" class="alignRt">Last Name:<span class="brightRed">
*</span></td>
<td><input name="lastname" type="text" class="formFields" id="lastname" value="<?php print "$lastname"; ?>" size="32" maxlength="20" /></td>
</tr>
<tr>
<td align="right" class="alignRt">Website:</td>
<td><strong>http://</strong> <input name="website" type="text" class="formFields" id="website" value="<?php print "$website"; ?>" size="40" maxlength="88" /></td>
</tr>
<tr>
<td align="right" class="alignRt">Youtube Channel:</td>
<td><strong>http://www.youtube.com/user/</strong> <input name="youtube" type="text" class="formFields" id="youtube" value="<?php print "$youtube"; ?>" size="32" maxlength="88" /></td>
</tr>
<tr>
<td align="right" class="alignRt">Email Address: <span class="brightRed">*</span></td>
<td><input name="email" type="text" class="formFields" id="email" value="<?php print "$email"; ?>" size="32" maxlength="48" /></td>
</tr>
<tr>
<td align="right" class="alignRt">Create Password:<span class="brightRed">
*</span></td>
<td><input name="pass" type="password" class="formFields" id="pass" maxlength="16" />
<span class="textSize_9px"><span class="greyColor">Alphanumeric
Characters Only</span></span></td>
</tr>
<tr>
<td align="right" class="alignRt"><br />
Human Check: <span class="brightRed">*</span></td>
<td><br /> <input name="humancheck" type="text" class="formFields" id="humancheck" value="Please remove all of this text" size="38" maxlength="32" />
</td>
</tr>
<tr>
<td> </td>
<td><p><br />
<input type="submit" name="Submit3" value="Submit Form" />
</p></td>
</tr>
</form>
</table>
<br />
<br /></td>
<td width="180" valign="top"><?php include_once "right_AD_template.php"; ?></td>
</tr>
</table>
<?php include_once "footer_template.php"; ?>
</body>
</html>