I have this registration form, when the user is finished with the form he will finally submit it, but I would like to check if the username and email is already there or not, easy right ? It's been 2 days trying to figure this out but no luck. Excuse me I'm not using the latest version of MySQL since this is the only version I learned at class. I will learn the improved one.
I've done a lot of research on Google, I found that this is some king of LOCK, that when we're inserting the table get locked ..
if(isset($_POST['button'])){
$query_global = mysql_query("SELECT Username FROM users WHERE Username = '".$_POST['username']."' ") or die(mysql_error());
$row = mysql_num_rows($query_global);
if($row == 1){
$error_username = "The username is already registered, please choose another one <br>";
}
$query_email = mysql_query("SELECT Email FROM users WHERE Email = '".$_POST['email']."' ") or die(mysql_error());
$row_email = mysql_num_rows($query_email);
if($row_email == 1){
$error_email = "This email : '".$_POST['email']."' is already registered ";
}
if(isset($_POST['Username'])) { $Username = $_POST['Username']; }
if(isset($_POST['email'])) { $email = $_POST['email']; }
$nom = $_POST['nom'];
$sexe = $_POST['sexe'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$adresse = $_POST['adresse'];
$ville = $_POST['ville'];
$pseudo = $_POST['pseudo'];
$mdp = $_POST['mdp'];
$date = $_POST['date'];
$profession = $_POST['profession'];
// location where initial upload will be moved to
$target = "images/" .$_FILES['uploaded']['name'] ;
// find thevtype of image
switch ($_FILES["uploaded"]["type"]) {
case $_FILES["uploaded"]["type"] == "image/gif":
move_uploaded_file($_FILES["uploaded"]["tmp_name"],$target);
break;
case $_FILES["uploaded"]["type"] == "image/jpeg":
move_uploaded_file($_FILES["uploaded"]["tmp_name"],$target);
break;
case $_FILES["uploaded"]["type"] == "image/pjpeg":
move_uploaded_file($_FILES["uploaded"]["tmp_name"],$target);
break;
case $_FILES["uploaded"]["type"] == "image/png":
move_uploaded_file($_FILES["uploaded"]["tmp_name"],$target);
break;
case $_FILES["uploaded"]["type"] == "image/x-png":
move_uploaded_file($_FILES["uploaded"]["tmp_name"],$target);
break;
default:
$error[] = 'Seulement les JPG, PNG ou GIF sont acceptés!.';
}
$error="";
if (!$error) {
$query = "INSERT INTO Users Values ('', '".$nom."', '".$sexe."', '".$email."', ".$tel.", '".$adresse."', '".$ville."', '".$pseudo."', '".$mdp."', curdate(), '$target', '".$date."', '".$profession."')";
$add_user = mysql_query($query) or die(mysql_error());
header('Location: Login/index.php');
}
}
//display any errors
if (!empty($error))
{
$i = 0;
echo "<p><span class='error'>";
while ($i < count($error)){
echo $error[$i].'<br />';
$i ++;}
echo "</span></p>";
}
Even if all this works out is there any way to stop the form from submitting when the inputs are wrong, I mean I've tried this in another file and it worked but even if the inputs are wrong the form gets submitted.
Can't wait to hear your answers.