PHP problem

  weisswolfen 15:03 29 Jan 2007

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.


// table name

// Random confirmation code

// values sent from form

// 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>";
} 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')";

// if suceesfully inserted data into database, send confirmation link to email

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

// send e-mail to ...

// 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
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']."';";


$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/

  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

Honor 9 Lite review

18 Best Adult Colouring In Books 2018

HomePod review

Les meilleures séries Netflix (2018)