Hi there, if anyone could lend me some help that would be great, basically i have a user signup form with recaptcha, that allows the user to sign up. This is all working fine, but now i have came round to using the server to check if the user exists but even with the new code I’ve coded it doesn’t work and still adds the user even if the username is taken, it then proceeds to add the user to a mailing list if a box was ticked, this all works fine also, its just the multiple user problem which I’ve tried to address, but can’t get the code to do what it’s supposed to.
Any ideas?
Here is my code:
[php]<?php
require_once(‘recaptchalib.php’);
$privatekey = “**********”;
$resp = recaptcha_check_answer ($privatekey,
$_SERVER[“REMOTE_ADDR”],
$_POST[“recaptcha_challenge_field”],
$_POST[“recaptcha_response_field”]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
"(reCAPTCHA said: " . $resp->error . “)”);
} else {
if (!isset( $_POST[‘user’])){
}
$con=mysqli_connect(“","","”, “*****”);
// Check connection
$sql = “SELECT COUNT(*) FROM users WHERE username = ‘{$_POST[‘user’]}’”;
$sql_result = mysql_query($sql);
}if(mysql_num_rows($sql_result) > 0 ) { //check if there is already an entry for that username
die (“Already taken”);
exit ();
} else {
//insert to table
mysqli_real_escape_string();
$email = $_POST[‘email’];
$user = $_POST[‘user’];
$signed = date(“Y-m-d”);
$password = $_POST[‘pass’];
$password = md5($password);
$dob = implode(’-’, $_POST[‘date’]);
$query = “INSERT INTO users (email, username, signedup, DOB, password) VALUES (’{$email}’, ‘{$user}’, ‘{$signed}’, ‘{$dob}’, ‘{$password}’)”;
mysqli_query($con, $query);
mysqli_close($con);
}
if (!isset( $_POST[‘mail’])){
header( ‘Location: *********l’ ) ;
}
$con2=mysqli_connect(“","","", "***”);
mysqli_real_escape_string();
$email = $_POST[‘email’];
$query2 = “INSERT INTO emails (emailad) VALUES (’{$email}’)”;
mysqli_query($con2, $query2);
mysqli_close($con2);
header( ‘Location: **********’ ) ;
?>[/php]