I’m trying to INSERT INTO a mySQL database and I’m getting this error on:
if (mysql_num_rows($login) == 1){
Here is the php, The php does add the user to the database. I can’t figure it out.
<?
session_start();
require("config.php");
$u = $_GET['username'];
$pw = $_GET['password'];
$pwh = $_GET['passwordhint'];
$em = $_GET['email'];
$zc = $_GET['zipcode'];
$check = "INSERT INTO family (loginName, email, password, passwordhint, location) VALUES ('$u', '$pw', '$pwh', '$em', '$zc')";
$login = mysql_query($check, $link) or die(mysql_error());
if (mysql_num_rows($login) == 1) {
$row = mysql_fetch_assoc($login);
echo 'Yes';exit;
} else {
echo 'No';exit;
}
mysql_close($link);
?>
Thanks,
You’re doing an
INSERTquery, so$loginwon’t contain any result set, it’s eithertrueorfalse.So instead of this:
You can either do this:
Or this:
Also, you don’t need this line anymore:
Unrelated to your question, but a very important thing to remember when doing SQL queries: you’ll need to escape all your
$_GETdata withmysql_real_escape_string()just before inserting, so as to prevent SQL injection.