0

I am trying to get some data out of my database for the first time, but for some reason it won't work. Here's my code:

$dbc = mysql_connect('censored', 'censored', 'censored', 'censored')
 or die ('Error connecting to MySQL server.');

$query = "SELECT * FROM apparel_img";
$result = mysqli_query($dbc, $query) 
    or die('Error querying database.');

while($row = mysqli_fetch_array($result)) {
    $product= $row['product'];
    $colour = $row['colour'];
    $file = $row['small'];

    echo '$product . $colour . $file';

}

mysqli_close($dbc);

I keep getting the 'Error querying database' line (I DO connect to the server), but am sure that the provided table exists.

Thanks in advance!

EDIT: Unfortunately I can't add images yet.

  • Are you setting the active database correctly as you connect? What do you get when you do a `SELECT DATABASE()` in your program? – O. Jones May 31 '14 at 21:32
  • 2
    mysqli can return errors. You should output them. Most likely the table name is wrong or it is the wrong database. And you can check your query in phpmyadmin. It will also show the error. – keiv.fly May 31 '14 at 21:33
  • The query works in PHP myAdmin! Just checked it! – user3684974 May 31 '14 at 21:41
  • Then the query is probably correct and there must be something wrong with the rest of your code. As keiv.fly said, you should check for the error result to see what the actual error is rather than us guessing at what might be wrong. You may wish to refer to http://stackoverflow.com/a/17053489/2385479 – Isaac Bennetch Jun 11 '14 at 01:32

1 Answers1

1

You are using mysql_connect to connect to the database but mysqli_* to run your query and interact with the data.. You cannot mix the two.

Robbert
  • 6,436
  • 5
  • 33
  • 60