sorry for my really dumb question.(I’m so new in this!).
I have a query (mysql, the programming language is php):
mysql_query("INSERT INTO user (id, f_name, l_name, email, user_name, password, b_day, gender, country, p_number, address, active)
VALUES ('NULL', '$_POST[fname]', '$_POST[lname]', '$_POST[email]', '$_POST[username]', '$_POST[password]', '$_POST[bday]', '$gender', '$_POST[country]', '$_POST[phone]', 'address', '0')")
or die("The username already exist");
that i need to apply some condition on it , sth like…
if (mysql_query done inserting successfully){
// do 1-
// 2-
// 3-
// 4-
}
else {die("The username already exist");
//and do
// 1-
// 2-
// 3-
// 4-
}
by the wayI set the username as unique in mysql database so will give an error if someone want to insert sth similar and i catch it as user already exist.
how can i do this?
Use of the mysql_* functions is discouraged. You should learn to use MySqli or PDO. However, I’ll just answer your question.
And you could do a query checking if the user already exists, before you insert anything.
You should sanitize and clean those $_POSTS.