+ 2

Data Already Exist

Hi, I make a registration form recently using PHP, how to produce an error/message when user input a name that already exist?

10th Jun 2018, 11:27 PM
boyd
boyd - avatar
6 odpowiedzi
+ 3
Okay I misunderstood your question. Well first of all you need to add new column called "id" with auto increment. You check if the row exist using SELECT query and rowCount() in PDO or mysqli_num_rows in mysqli
10th Jun 2018, 11:48 PM
Toni Isotalo
Toni Isotalo - avatar
+ 3
$pre = $db->prepare("SELECT id FROM users WHERE name=:name) $pre->bindParam(":name", $name); $pre->execute(); if($pre->rowCount()) { echo "Name already exists"; } else { }
10th Jun 2018, 11:50 PM
Toni Isotalo
Toni Isotalo - avatar
+ 2
What do you mean exist? How do you store them. Show me your table.
10th Jun 2018, 11:32 PM
Toni Isotalo
Toni Isotalo - avatar
+ 2
oh ok tq ^^
10th Jun 2018, 11:48 PM
boyd
boyd - avatar
+ 1
lets just assume I have a database name "login" with table named "users" with 3 column which is "email", " name", "password" with value "boyd@email.com", " boyd", "1234" respectively. And then, when another user register, he/she put the same name on the register form and submit, my code will scan the table in the database if the name already exist.
10th Jun 2018, 11:40 PM
boyd
boyd - avatar
+ 1
btw i use xampp and mysql
10th Jun 2018, 11:42 PM
boyd
boyd - avatar