No data to display


 $email= trim($_POST['email']);
	$password = trim($_POST['password']);
	
	$sql = "select 		email,password, from customer where email = '".$email."'    ";
	 $result = $conn->query($sql);

if ($result->num_rows > 0) {
// output data of each row THIS IS WHERE YOU PRINT EACH ROW FROM THE QUERY 
while($row = $result->fetch_assoc()) {
    echo "   - Name: " . $row["firstname"]. " " .        $row["lastname"]. "<br>";
  }
 } else {
 echo "0 results";
}
	

So tempting to just write “No question to answer”. But anyway…

How do you expect it to display the values for firstname and lastname when you didn’t select them in your query? That query returns only the two columns that you specified - email and password - so anything else should give you an “undefined index” error or just a blank string. If the spurious comma after password doesn’t throw a syntax error, that is.

If the question was about something else, sorry for guessing wrongly. :slight_smile:

1 Like

i selected firstname and lastname nothing show up

How many rows does the query return? Does the query even execute? Your code doesn’t check to see whether it has.

 $email= trim($_POST['email']);
	$first_name = trim($_POST['first_name']);
	
	$sql = "select 		email,first_name from users where email = '".$email."' , first_name = '".$first_name."'  ";
	 $result = $conn->query($sql);
    if ($result->num_rows > 0) {
        // output data of each row
        while ($row = $result->fetch_assoc()) {
            echo "  - Name: " . $row["email"] . " " . $row["first_name"] . "<br>";
        }
    } else {
        echo "0 results";
    }
    $conn->close();
  
	
	
 }
0 results

So, what’s in $email and $first_name, and is there a row in your database with that email address and first-name combination? Can you use that syntax for two parameters in your query, or do you need to specify OR or AND?

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `user_id` int(5) NOT NULL,
  `first_name` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `username` varchar(25) NOT NULL,
  `password` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


Seems this is a “no” - if I try a query with two conditions separated by a comma, I get a syntax error. I’m surprised you don’t get an error when you check num_rows. Change it to use AND or OR, as required.

i added AND still zero is coming out

OK, so how many of the rows in your table match the values you are inputting? Are there any spurious characters in there? Perhaps you could show a sample of what you’re searching for, and what is in the table, covering anything sensitive up of course. Presumably when you added the AND, you removed the comma?

Hang on a minute, is this PDO?

if ($result->num_rows > 0) {

should give you

( ! ) Notice: Undefined property: PDOStatement::$num_rows in whatever.php on line 7

Turn on error reporting and run the code again.

comma where let make clear what i want based on posts in log in email and password display that but in same line i have first_name which i want fetch

no no

What are you replying to here?

:smile:

The comma that you had where the AND should have been. You’ve added the “AND”, have you removed the comma?

Show some data please, and the latest version of the code.

$email= trim($_POST['email']);
	$password = trim($_POST['password']);
	
	$sql = "select 		email,password from users where email = '".$email."' AND password = '".$password."'  ";
	 $result = $conn->query($sql);
    if ($result->num_rows > 0) {
        // output data of each row
        while ($row = $result->fetch_assoc()) {
            echo "  - Name: " . $row["email"] . " " . $row["password"] . "<br>";
        }
    } else {
        echo "0 results";
    }
    $conn->close();
  
	
	
 }	

OK, so it’s changed from first_name to password now. Don’t you encrypt the passwords when you store them in the database?

OK, so do you encrypt the passwords when you store them? If you, this won’t work.

Either way, need to see some data now the code might not be an issue. Presumably this isn’t PDO, then?

wait a minute in db password is hash