Obi Justin February 2016

How can I make my query output the row value instead of the field value

Below is my code. It ouputs the field names instead of the row values.

Please how can I make it to output the rows I have on the database?

<?php 
$conn_error = "Could not connect";
$correct = "all correct!";
$host = "localhost";
$username = "Ifacool";
$password = "1234";

$mysql_db = "ifacool";

if (!mysql_connect($host, $username, $password) || !mysql_select_db                      ($mysql_db)) {
die ($conn_error);
}
else{
       echo $correct . '<br>'; 
}
$query = "SELECT 'firstname', 'password' FROM ifacooltable WHERE ID = 1 ";
if ($query_run = mysql_query($query)) {
    while ($query_row = mysql_fetch_assoc ($query_run)){
        $firstname = $query_row['firstname'];
        $password = $query_row['password'];
        echo $firstname . ' password is ' . $password . ' exactly.<br>';
    }
} else {
    echo "query failed";
}
?>

Answers


potashin February 2016

Use backticks ` instead of single quotes ' to escape identifiers in MySQL – now you just select plain strings:

$query = "SELECT `firstname`, `password` FROM `ifacooltable` WHERE `ID` = 1 ";

Post Status

Asked in February 2016
Viewed 3,861 times
Voted 5
Answered 1 times

Search




Leave an answer