mysql - what is the code in php to check if user already Exist or not? -
i'm new in php , mysql. i'm trying check if user taken or not. if it's taken won't added database. however, tried lot of code trick none of code used worked. i'm not sure i'm doing wrong. have right now:
<?php include 'db_settings.php'; db_connect(); //escape variables security $user = mysqli_real_escape_string($con, $_post['user']); $pass = mysqli_real_escape_string($con, $_post['pass']); $email = mysqli_real_escape_string($con, $_post['email']); $sql="insert users (user, pass, email) values ('$user','$pass', '$email')"; if (!mysqli_query($con,$sql)) { die('error: ' . mysqli_error($con)); } echo "1 record added</br>"; mysqli_close($con); echo "<a href='sign-up.html'>sing-up again!</a></br>"; echo "<a href='index.html'> go home </a>"; ?>`
i know code don't have checking function user if taken or not because deleted codes it. if it's possible if guys me appreciate it.
your code seems fine 1 thing run below code on mysql console or phpmyadmin
alter table `users` add unique ( `user` );
Comments
Post a Comment