I am very new to php and mysql. I have created a form that allows a user to register. What i'm trying to do is have, when the user clicks submit, first check to make sure both passwords field match, but then i am wanting it to check the mysql table to make sure someone with the same cid isn't already registered. my code is below. Any help would be greatly appreciated.
//insert information
$query="SELECT cid = " . $_POST[cid] . "FROM userinfo";
If($_POST[password] == $_POST[password2]) //ensures passwords match before submission
{
If($query == $_POST[cid]) //checks to see if user is already registered.
{
die("Your CID is already registered.");
}
else
{
$sql="INSERT INTO userinfo(firstn, lastn, cid, email, psswd, rating)
VALUES
('$_POST[fname]','$_POST[lname]','$_POST[cid]','$_POST[email]', '$_POST[password]', '$_POST[rating]')";
}
}
else
{
die("Your passwords did not match, please go back and re-enter");
//check to see if information was sent, if not dispaly error.
}
When i test it, the form does everything it should except compare the values from the user entered "Cid's" to the ones in the database already. I'm sure the error lies in the following line of code:
$query="SELECT cid = " . $_POST[cid] . "FROM userinfo";
i'm just not sure of how to write it and a google search didn't clear anything up. Thanks again