PHP problem

  weisswolfen 15:03 29 Jan 2007
Locked

I'm trying to get a Signup form working with php and mysql. The form and email verification all worked well until I tried to insert a piece of script to have -username- checked if is already there.This is the all script:(the culprit is- CHECK IF USERNAME IS TAKEN- everything else is fine) What is missing? Thanks.

*****
?
include('config.php');

// table name
$tbl_name=temp_members_db;

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

// values sent from form
$username=$_POST['username'];
$name=$_POST['name'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$password=$_POST['password'];
$repeatpassword=$_POST['repeatpassword'];
$postcode=$_POST['postcode'];


// check if the username is taken
$check = "select id from $table where username = '".$_POST['username']."';";
$qry = mysql_query($check) or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
echo "Sorry, there the username $username is already taken. br>";
echo " a href=register.html>Try again /a>";
exit;
} else {


// Insert data into database
$sql="INSERT INTO $tbl_name(confirm_code,username, name,lastname, email, password,repeatpassword, postcode)VALUES('$confirm_code','$username', '$name','$lastname', '$email', '$password','$repeatpassword', '$postcode')";
$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: OpenDoor TestingMySQLsignupform your email>";

// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="click here=$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";
}

?>

********

  harristweed 20:09 29 Jan 2007

try changing:
$check = "select id from $table where username = '".$_POST['username']."';";

to:

$username=trim($_POST[username]);
$check = "select id from $table where username = '$username' ";

  weisswolfen 12:09 30 Jan 2007

Thanks harristweed I'm going to ckeck it out.
I'm pretty new to DB , I'm looking to have end user to login to an individual account instead to go to a general membership area as it is now. Do you know of any tutorial explaining
how to do it/
Thanks

  harristweed 09:06 31 Jan 2007

I don't know of any tutorials specifically but there is a lot of useful stuff here.

click here

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

OnePlus 5 review

See the work of famous artists playing with toys

iPad Pro 10.5in (2017) review

Comment faire une capture d’écran sur un Mac ?