Page 1 of 1

Error on register scipt

Posted: Thu Jun 08, 2006 7:46 pm
by 4Boredom
I keep getting errors here on my signup page

can anyone help?


There are 3 files attached....

Signup.php

Code: Select all

<?php 
# starting the session here 
session_start(); 

# this prevents a user from typing or pasting a URL string 
# into their browser to get to this page. If the $first_name 
# variable is empty, then they log in like everyone else. 
?>

<?php require("header.php"); ?>

<center>
<b>New User Signup</b><br><br>

<form name=form1 method=post action=register.php> 
  <table width=100% border=0 cellpadding=4 cellspacing=0 align="center"> 
    <tr>  
      <td width=24% align=left valign=top>First Name</td> 
      <td width=76%><input name=first_name type=text id=first_name></td> 
    </tr> 
    <tr>  
      <td align=left valign=top>Last Name</td> 
      <td><input name=last_name type=text id=last_name></td> 
    </tr> 
    <tr>  
      <td align=left valign=top>Email Address</td> 
      <td><input name=email_address type=text id=email_address></td> 
    </tr> 
    <tr>  
      <td align=left valign=top>Desired Username</td> 
      <td><input name=username type=text id=username></td> 
    </tr> 
     <tr>  
      <td align=left valign=top>Desired Password</td> 
      <td><input name=username type=text id=password></td> 
    </tr> 
      <td align=left valign=top> </td> 
      <td><input type=submit name=Submit value=Join Now!></td> 
    </tr> 
  </table> 
</form> 
</body> 
</html>
db.php

Code: Select all

<?  
# database connection scripts 
# the next 4 lines you can modify 
$dbhost = 'localhost'; 
$dbusername = 'hidden'; 
$dbpasswd = 'hidden'; 
$database_name = 'hidden'; 

#under here, don't touch! 
$connection = mysql_connect("$dbhost","$dbusername","$dbpasswd")  
    or die ("Couldn't connect to server."); 
$db = mysql_select_db("$database_name", $connection) 
    or die("Couldn't select database."); 
?>
Register.php

Code: Select all

<? 

include 'db.php'; 
# grab the POST variables from the HTML form
$first_name = $_POST['first_name']; 
$last_name = $_POST['last_name']; 
$email_address = $_POST['email_address']; 
$username = $_POST['username']; 
$password = $_POST['password']; 

# Any escaped characters?
$first_name = stripslashes($first_name); 
$last_name = stripslashes($last_name); 
$email_address = stripslashes($email_address); 
$username = stripslashes($username); 
$password = stripslashes($password); 

# Any errors in the posted fields? 
if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){ 
    echo 'You did not submit the following required information! <br />'; 
    if(!$first_name){ 
        echo "First Name is a required field. Please enter it below.<br />"; 
    } 
    if(!$last_name){ 
        echo "Last Name is a required field. Please enter it below.<br />"; 
    } 
    if(!$email_address){ 
        echo "Email Address is a required field. Please enter it below.<br />"; 
    } 
    if(!$username){ 
        echo "Desired Username is a required field. Please enter it below.<br />"; 
    } 
    include 'signup.php'; 
    exit(); 
} 
     
# does this user already exist in the database?  
 $sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'"); 
 $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'"); 
  
 $email_check = mysql_num_rows($sql_email_check); 
 $username_check = mysql_num_rows($sql_username_check); 
  
 if(($email_check > 0) || ($username_check > 0)){ 
     echo "Please fix the following errors: <br />"; 
     if($email_check > 0){ 
         echo "<strong>Your email address has already been used by another member in our database. Please use a different email address!<br />"; 
         unset($email_address); 
     } 
     include 'signup.php'; // Shows the form again!
     exit(); 
 } 
  

# Enter info into the Database. 

$info2 = htmlspecialchars($info); 

$sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, signup_date)"); 



if(!$sql){ 
    echo 'There has been an error creating your account. Please contact the webmaster.'; 
} else { 
    $userid = mysql_insert_id();
    // Let's mail the user! 
    $subject = "Your 4Boredom.com Membership";
    $message = "Dear $first_name $last_name, 
    You are now registered at our website, http://www.4boredom.com! 
     
    You are now able to login with the following information: 
    Username: $username 
    Password: $password 
    Please keep this username and password in a location that is easily accessible by you. 
     
    Thanks! 
    Derek Lemire
	4boredom.com
     
    This is an automated response, please do not reply!"; 
     
    mail($email_address, $subject, $message, "From: MyWebSite<derek@4boredom.com>\nX-Mailer: PHP/" . phpversion()); 
    echo 'Your membership information has been mailed to your email address! Please check it and follow the directions!'; 
} 
?>
[/url]

Posted: Thu Jun 08, 2006 11:29 pm
by feyd
There's absolutely no reason to have created another thread for this. Locked.