PDA

View Full Version : PHP - Register/Login Script - Mysql


mhauth
04-18-2007, 07:18 AM
Hey everyone!

I am very new to php. Hopefully its not to obvious. I am trying to create a signup page that will input all following fields into a database I call evomembers. I want users to have to verify their registration by email.

When I submit my signup i get ths error

"Not found your email in our database Cannot send Confirmation link to your e-mail address"

I would think this would be more for something along the lines of retrieving a password.


If I have left our a a pages code that you need let me know.

(signup.php)
<table width="320" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="320"><form name="form1" method="post" action="signup_ac.php">
<table border="0" cellspacing="4" cellpadding="0">
<tr>
<td>First Name</td>
<td>:</td>
<td><input name="firstname" type="text" id="fistname" size="30"></td>
</tr>
<tr>
<td>Last Name </td>
<td>:</td>
<td><input name="lastname" type="text" id="lastname" size="30"></td>
</tr>
<tr>
<td>E-mail</td>
<td>:</td>
<td><input name="email" type="text" id="email" size="30"></td>
</tr>
<tr>
<td>Desired Username </td>
<td>:</td>
<td><input name="username" type="text" id="username" size="30"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="password" id="password" size="30"></td>
</tr>
<tr>
<td>Address</td>
<td>:</td>
<td><input name="address" type="text" id="address" size="30"></td>
</tr>
<tr>
<td>City</td>
<td>:</td>
<td><input name="city" type="text" id="city" size="30"></td>
</tr>
<tr>
<td>State</td>
<td>:</td>
<td><input name="state" type="text" id="state" size="30"></td>
</tr>
<tr>
<td>Zip Code </td>
<td>:</td>
<td><input name="zip" type="text" id="zip" size="15"></td>
</tr>
<tr>
<td>Handicap</td>
<td>:</td>
<td><input name="handicap" type="text" id="handicap" size="5"></td>
</tr>
<tr>
<td>Rounds Per Month </td>
<td>:</td>
<td><input name="roundsmonth" type="text" id="roundsmonth" size="5"></td>
</tr>
<tr>
<td>Age</td>
<td>:</td>
<td><input name="age" type="text" id="age" size="5"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit">
&nbsp;
<input type="reset" name="Reset" value="Reset"></td>
</tr>
</table>
</form></td>
</tr>
</table>


(signup_ac.php)
<?
include('config.php');

// table name
$tbl_name=temp_members;

// Random confirmation code
$confirm_code=md5(uniqid(rand()));

// values sent from form
$firstname=$_POST['firstname'];
$lastname=$_POST['firstname'];
$email=$_POST['email'];
$password=$_POST['password'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$handicap=$_POST['handicap'];
$roundsmonth=$_POST['roundsmonth'];
$age=$_POST['age'];


// Insert data into database
$sql="INSERT INTO $tbl_name(confirm_code, firstname, lastname, email, password, address, city, state, zip, handicap, roundsmonth, age,)VALUES('$confirm_code', '$firstname', '$lastname', '$email', '$password', '$address', '$city', '$state', '$zip', '$handicap', '$roundsmonth', '$age',)";
$result=mysql_query($sql);

// if suceesfully inserted data into database, send confirmation link to email
if($result){

// ---------------- SEND MAIL FORM ----------------

// send e-mail to ...
$to=$email;

// Your subject
$subject="Your confirmation link here";

// From
$header="from: your name <your email>";

// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://www.evolutionofgolf.com/confirm.php?passkey=$confirm_code";

// send email
$sentmail = mail($to,$subject,$message,$header);

}

// if not found
else {
echo "Not found your email in our database";
}

// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}

?>

Thank you very much in advance.

rafiki
04-18-2007, 11:01 AM
use mysql_error() (http://www.php.net/mysql-error) to see why its not inseting data to the database

aedrin
04-18-2007, 04:16 PM
I think an example would be helpful.


$result = mysql_query("SELECT * FROM randomtable") or die("Error: " . mysql_error());


Executing your query in this format will print out any errors it came across.

I suggest you turn on error reporting, and set it to the highest level (this would be in your server's .ini file). You'll come across a few warnings/errors. (Such as using undefined variables - $sentmail).

rafiki
04-18-2007, 07:23 PM
$sentmail = mail($to,$subject,$message,$header);
$sentmail is set but maybe he should of added the if for it in the same if statement that its being set in

<?
include('config.php');

// table name
$tbl_name=temp_members;

// Random confirmation code
$confirm_code=md5(uniqid(rand()));

// values sent from form
$firstname=$_POST['firstname'];
$lastname=$_POST['firstname'];
$email=$_POST['email'];
$password=$_POST['password'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$handicap=$_POST['handicap'];
$roundsmonth=$_POST['roundsmonth'];
$age=$_POST['age'];


// Insert data into database
$sql="INSERT INTO $tbl_name(confirm_code, firstname, lastname, email, password, address, city, state, zip, handicap, roundsmonth, age,)VALUES('$confirm_code', '$firstname', '$lastname', '$email', '$password', '$address', '$city', '$state', '$zip', '$handicap', '$roundsmonth', '$age',)";
$result=mysql_query($sql);

// if suceesfully inserted data into database, send confirmation link to email
if($result){

// ---------------- SEND MAIL FORM ----------------

// send e-mail to ...
$to=$email;

// Your subject
$subject="Your confirmation link here";

// From
$header="from: your name <your email>";

// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://www.evolutionofgolf.com/confirm.php?passkey=$confirm_code";

// send email
$sentmail = mail($to,$subject,$message,$header);
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
}

// if not found
else {
echo "Not found your email in our database";
}



?>

aedrin
04-18-2007, 08:46 PM
That doesn't matter really.

And usually your business code would go before any HTML, so you'd put the message later on in the file.