0

I am a beginner, and just took a few lessons from this youtube course:

https://www.youtube.com/watch?v=TSX72_O7QYY&index=116&list=PL442FA2C127377F07

I have written this code.

<?php

$db_host = 'localhost';
$db_username = 'root';
$db_password = 'awesome11';
$db_connError = '<br>Cannot connect<br>';
$db_connConf = '<br>Connect to db<br>';
$db_name = 'codelib';
$db_table = 'codes';
$db_conn = mysqli_connect($db_host,$db_username,$db_password,$db_name);

if($db_conn){
    mysqli_select_db($db_conn,$db_table);
    echo $db_connConf;
}else{
    echo $db_connError;
}

$query = "SELECT 'id' FROM `codes'";

if($run = mysqli_query($db_conn,$query)){

    echo 'query is ok';

}else{
    echo 'query failed';
}
?>

The function mysqli_connect() works fine. But msqli_query() does not work. It always says that query failed.

Besides msqli_query(), the simple msqli() also never works! I cannot even create a variable like this one:

$mysqli = new mysqli($db_host,$db_username,$db_password,$db_name)
sisanared
  • 4,175
  • 2
  • 27
  • 42
  • JUST A LITTLE BACKGROUN --> this is not the first code i am trying to run on my localhost. I have already run hundreds of codes. This is the first time i have faced this problem, and thought why shouldn't I ask the great minds on stackoverflow. Please help me out – Hassan Malik Oct 16 '16 at 06:15

1 Answers1

1

You have a typo in your query line, change the following:

$query = "SELECT 'id' FROM `codes'";

to this:

$query = "SELECT `id` FROM `codes`";

You used a single quote (') instead of reverse quote (`)

sisanared
  • 4,175
  • 2
  • 27
  • 42