Jump to content

mysql_result(): supplied argument is not a valid MySQL result resource.


StefanPakaski

Recommended Posts

I have trying to find what i am doing wrong but i cant find it. When i try to log in on my page i get this.

 

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /www/zzl.org/s/i/m/simago/htdocs/func/user.func.php on line 14

 

Here is the user.func script:

 

<?php
function logged_in() {
  return isset($_SESSION['user']);
}
session_start();

mysql_connect ('localhost', '********', '************');
mysql_select_db('*********');


function login_check($email, $password){	
$email = mysql_real_escape_string($email);
    $password = mysql_real_escape_string($password);
$login_query = mysql_query("SELECT COUNT(`user_id`) as `count`, `user_id` FROM `users` WHERE? `email` = '$email' AND `password` = '".md5($password)."' ");
return (mysql_result($login_query, 0) == 1) ? mysql_result($login_query, 0, 'user_id') : false;

}

function user_data() {

}

function user_register($email, $name, $password) {
  $email = mysql_real_escape_string($email);
  $name = mysql_real_escape_string($name);
  mysql_query("INSERT INTO `users` VALUES ('', '$email', '$name', '".md5(password)."')");
  return mysql_insert_id();
}

function user_exists() {
  
}

?>

 

This is my line 14:

 

return (mysql_result($login_query, 0) == 1) ? mysql_result($login_query, 0, 'user_id') : false;

 

Please help!

Link to comment
Share on other sites

What's actually doing a "?" question mark immediately after "WHERE"  clause ?

$login_query = mysql_query("SELECT COUNT(`user_id`) as `count`, `user_id` FROM `users` WHERE? `email` = '$email' AND `password` = '".md5($password)."' ");

Link to comment
Share on other sites

What's actually doing a "?" question mark immediately after "WHERE"  clause ?

$login_query = mysql_query("SELECT COUNT(`user_id`) as `count`, `user_id` FROM `users` WHERE? `email` = '$email' AND `password` = '".md5($password)."' ");

 

It isn't there in the script so it must have been when i pasted it.

 

I solved this problem but now i get another error.

 

Warning: Wrong parameter count for mysql_result() in /www/zzl.org/s/i/m/simago/htdocs/func/user.func.php on line 16

 

<?php

function logged_in() {
  return isset($_SESSION['user']);
}
session_start();



error_reporting(E_ALL);

function login_check($email, $pass) {
    $email = mysql_real_escape_string($email);
    $login_query = mysql_query("SELECT COUNT (`user`) as `count`, `userid` FROM `users` WHERE `email`='$email' AND `pass`='".md5($pass)."'");
    return (mysql_result
($login_query) == 1) ?
mysql_result($login_query) : false;


}

function user_data() {

}

function user_register($email, $name, $pass) {
  $email = mysql_real_escape_string($email);
  $name = mysql_real_escape_string($name);
  mysql_query("INSERT INTO `users` VALUES ('', '$email', '$name', '".md5($pass)."')");
  return mysql_insert_id();
}

function user_exists() {
  
}

?>

 

My line 16 is:

 ($login_query) == 1) ?

 

I am new to php so please give an answer that i might understand.

 

Thanks folks!

Link to comment
Share on other sites

That should not work, cannot believe that it does.  mysql_result REQUIRES 2 arguments, the resource, and the row.  The field is optional.  I normally do not repeat myself, but you are just setting yourself up for problems in the future, as this is bad coding practices. (*NOTE: when viewing the manual, any arguments surrounded in [ and ] is optional, they will also have the default value given, in this case it is 0 for the 3rd argument).

//at the very least, gives you the count.
mysql_result($login_query,0);
//if you want the userid;
mysql_query($login_query,0,1);

 

I personally would also check to see if the query returned rows, instead of checking to make sure it wasn't false.  Not real sure why you would check to see if a result resource was equal to 1, when it could never equal 1 since it is a result resource.  It can exists, therefore equal TRUE, or not exist therefore equal FALSE.  Once again, that is my personal taste, I've seen plenty of "coders" that check it the way you have, I just don't agree that it is right.

Link to comment
Share on other sites

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.