troubleshooting Question

Help to run a simple query in PHP

Avatar of hidrau
hidrauFlag for Brazil asked on
PHPWeb Development
17 Comments3 Solutions139 ViewsLast Modified:

after almost two hours trying to understand where is the error, I am getting sick with the code and I hope someone here can help me.

I need to make a simple query and return the value, to check if user and password is ok. But my function only returns -1

I checked the table, fields, connections and all is ok. Where is the error:

this is my function

function login_sistema($uso, $senha){
    global $servername, $username, $password, $dbnome;
	// Create connection
	$conn = new mysqli($servername, $username, $password, $dbname);
	// Check connection
	if ($conn->connect_error) {
		die("Connection failed: " . $conn->connect_error);
	$sql = " SELECT * FROM CADUSO ";
	$sql = $sql . " WHERE NOME='" .$uso . "'";
    $rs= $conn->query($sql);  

    if ($rs->num_rows > 0) {	
		if ($row("senha")==$senha){
			$id = 1;
		} else {
			$id = -2;
	} else {   
		$id = -1;		
    return $id;		

Thanks a lot
Join our community to see this answer!
Unlock 3 Answers and 17 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 17 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros