1

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,

2 Answers 2

4

You're doing an INSERT query, so $login won't contain any result set, it's either true or false.

So instead of this:

if (mysql_num_rows($login) == 1) {

You can either do this:

if (mysql_affected_rows($link) == 1) {

Or this:

if ($login == true) {

Also, you don't need this line anymore:

$row = mysql_fetch_assoc($login);

Unrelated to your question, but a very important thing to remember when doing SQL queries: you'll need to escape all your $_GET data with mysql_real_escape_string() just before inserting, so as to prevent SQL injection.

Sign up to request clarification or add additional context in comments.

Comments

0

mysql_query() returns True/False for INSERT, UPDATE, DELETE, DROP...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.