Hello!
This is my first post here, hehe. Seems to be a great site.
Anyways, I'm quite new in PHP, but it's fun and I think I'm learning quite fast :)
There's appeared a problem for me now though, and I can't see what the problem is...?
I have made a form, which posts values to my php-page. This page inserts the values to the database, and that works just fine. But now I wanted to add the function to check if a value is already in use; in this case the value you entered in the email field.
So I found out about the num_rows function and as far as I know, it should do the thing.
I've made the part about num_rows bold.
So what I want to do is; check if the value I enter in the email field, in my form, already exists in my database/table. If numrows > 0, then it does exist, and my command is interrupted. Else it inserts the values from the form into my table and database. Thanks on advance!
<?php
include 'connect.php';
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$pass = $_POST["pass"];
$email = $_POST["email"];
$age = $_POST["age"];
** $sql_select="SELECT info
FROM users
WHERE fname
='$email'";
$result = mysql_query($sql_select);
if(mysql_num_rows($result) > 0 ) {
echo "The email you entered is already in use, please try again.";
} else {**
$sql = "INSERT INTO `users`.`info` (`fname`, `lname`, `pass`,`email`,`age`)
VALUES ('$fname', '$lname', '$pass', '$email', '$age')";
mysql_query($sql);
}
mysql_close($link);
?>