Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /data/9/0/24/113/676928/user/690291/htdocs/inc/_up_index1.php on line 40

This is the error i get every time when any of my php scripts try to read/write in my mysql data base.

This is _up_index1.php

<?

$test_act['new_tranzaction']="OK";



$test_act['tranzaction_details_started']="OK";

$test_act['tranzaction_details_pointing']="OK";

$test_act['accept_tranzaction']="OK";

$test_act['reject_tranzaction']="OK";

$test_act['tranzaction_details']="OK";

$test_act['payment']="OK";

if(!$test_act[$act]){

$act="tranzactions";
}



if(session_is_registered("valid_user")){

$act=$act;}

else{

$errormsg="";

if($do=="login"){

$sql="select * from escrow_user where user='$user' and pass=PASSWORD('$pass') LIMIT 1";

$result=mysql_query("$sql");

$n=mysql_num_rows($result);    /// LINE 40

if($n==0){

$errormsg="Invalid Log In";

$title="LOG IN";

$act="login";}

else{

$rand=mysql_fetch_array($result);

$valid_user=$user;

$valid_email=$rand[email];

session_register("valid_user");

session_register("valid_email");

$title="your account";

$act=$act;}

}

else{$act="login";

$title="LOG IN";

}

}

?>

I am a newbie in php so if anyone can help me fix this website it will be highly apreciate.

thanks

Dani AI

Generated

Short diagnosis and immediate check: that warning means the value passed to the row-count call is not a valid result resource because the preceding query returned FALSE. Common root causes are a failed DB connection, a syntax/quoting error in the SQL, or a mismatched table/column name. In the code posted by the query result is used directly; the next step is to stop assuming the query succeeded and log the real DB error (or the mysqli/PDO error) so the cause is visible.

Minimal, safer pattern (mysqli + prepared statements + modern password handling):

$mysqli = new mysqli($host, $db_user, $db_pass, $db_name);
if ($mysqli->connect_errno) { error_log("MySQL connect error: " . $mysqli->connect_error); exit; }

$stmt = $mysqli->prepare("SELECT id,email,password_hash FROM escrow_user WHERE user = ? LIMIT 1");
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->store_result();

if ($stmt->num_rows === 1) {
    $stmt->bind_result($id, $email, $hash);
    $stmt->fetch();
    if (password_verify($submitted_pass, $hash)) {
        session_start();
        $_SESSION['valid_user']  = $username;
        $_SESSION['valid_email'] = $email;
    } else {
        /* invalid password */
    }
} else {
    /* user not found */
}

Practical tips and security notes: 's idea of changing the SQL to match plaintext passwords may “fix” the immediate query failure if the DB stores plain text, but it is insecure. Verify what format passwords are stored in the DB before changing queries. Add logging of DB errors (mysqlerror or $mysqli->error) while debugging, enable full error reporting on a dev box only, and move away from deprecated mysql* calls and session_register/session_is_registered: use mysqli or PDO and the $_SESSION superglobal. Finally, run the same SELECT manually in the database client to confirm the SQL is valid — that often reveals the exact reason mysql_query returned FALSE.

Try this im sure it will work...
$sql="select * from escrow_user where user='$user' and pass='$pass' LIMIT 1";

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.