Jump to content

Recommended Posts

If the fname, lname and id the user fills into the form match what is in the database I want this to go on to the next bit of code but... even though they are a match I am getting the error message  that 'this doesn't work try again'.

 

 

 

if($login != '') {

  $qry = "SELECT fname, lname, login FROM user WHERE fname='$fname' AND lname='$lname' AND login='$login'";

  $result = mysql_query($qry);

  if($result) {

      if(mysql_num_rows($result) != 3) {

        $errmsg_arr[] = 'this doesn't work try again';

        $errflag = true;

      }

      @mysql_free_result($result);

  }

  else {

          die("Query failed");

  }

}

 

 

 

Is my !=3  wrong?  I figure this should return 3 rows, no?  So if the result doesn't equal 3 then something went wrong and the code shouldn't continue.

 

That was my logic.  Where have I gone wrong!!??

 

Thanks for any help!

Link to comment
https://forums.phpfreaks.com/topic/241323-query-failed-num_rows/
Share on other sites

What result is echoed when you echo mysql_num_rows($result)? I'm guessing it's going to be either 0 or 1. mysql_num_rows() returns the number of records the query retrieves, not the number of individual fields.

Ok but regardless of my lack of coding knowledge here (which is extensive - the lack that is...)

 

If it returns only the records then if the three fields match up successfully it should return 1 record, right?

 

So if I change this to == 1  - that should work right?

 

thanks

I might have to rethink this whole thing...  I am reallllly new to this and I'm trying to put together this going through tutorials and examples I can find online.

 

I am starting with three bits of information about a member in the database to begin with before any registration has begun as I am creating something for a specific group.

 

When they come to register at the site I was going to use that information to verify who they were before allowing them to continue with the registration.

 

So this part of the code was to authenticate the user before updating the database with a couple other require bits of info in the registration form.

 

Is there an obvious thing I'm missing here?

 

tx

 

 

 

OK! so I am good and past that hurdle.

 

The query works but when I get to the next step where the extra bits of info I am gathering are to be inserted into the database I get "Query failed here2".

 

 

$qry = "INSERT INTO user (email, password) VALUES ('$email', '".md5($_POST['password'])."')";

$result = @mysql_query($qry);

 

if($result) {

header("location: register-success.php");

exit();

}else {

die("Query failed here2");

}

 

 

Other than the fact I haven't separated the login in info and the other info into two separate tables yet... Should this not work?

 

Thanks!!

 

 

 

Both sets of code together:

 

 

 

 

if($login != '') {

$qry = "SELECT fname, lname, login FROM user WHERE fname='$fname' AND lname='$lname' AND login='$login'";

$result = mysql_query($qry);

if($result) {

if(mysql_num_rows($result) != 1) {

$errmsg_arr[] = 'this doesn't work try again';

$errflag = true;

}

@mysql_free_result($result);

}

else {

die("Query failed here1");

}

}

 

if($errflag) {

$_SESSION['ERRMSG_ARR'] = $errmsg_arr;

session_write_close();

header("location: register-form.php");

exit();

}

 

 

$qry = "INSERT INTO user (email, password) VALUES ('$email', '".md5($_POST['password'])."')";

$result = @mysql_query($qry);

 

if($result) {

header("location: register-success.php");

exit();

}else {

die("Query failed here2");

}

 

 

Thanks for any help.  If I can get past this... I'm almost there!

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.