-1

The code below is used to retrieve some simple data from a MySQL table named people's names.

<?php
$user = "root"; //Connection to DB  
$pass = "";
$db = "testdb";
$link = new mysqli('localhost' , $user , $pass, $db) or die("unable to connect");

$query = "select * from  people's names";
if ($result = mysqli_query($link, $query)){

    echo "It Worked!";

} else {

    echo "it failed!";  

}
?>

I checked the code over and over again and have searched every corner of the internet to find an answer but can't seem to prevent the inevitable "it failed!" message when I load the page. Any help would be greatly appreciated. Thanks -Dylan.

wogsland
  • 9,106
  • 19
  • 57
  • 93

3 Answers3

4

In Mysql ' is a special character you need to escape it in your query. I would avoid such in table names or escape it with back ticks.

A good question on naming conventions for mysql Is there a naming convention for MySQL?

MySql Reference

Community
  • 1
  • 1
PoX
  • 1,229
  • 19
  • 32
2

people's names is not a valid table name. That's likely your issue, assuming your connection parameters are correct.

wogsland
  • 9,106
  • 19
  • 57
  • 93
1

Adding to wogsland and Pox their answers.

I would say names is already plural, so you don't need to pluralize people. So a good table name could be

people_names

depending on other conventions you could also use

peopleNames
davejal
  • 6,009
  • 10
  • 39
  • 82