2

I am trying to display a certain row of one of the tables in my database.

Here is my code for it:
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
else printf("Connection Successful");

mysql_select_db('magento');
$query = "SELECT * FROM poll_answer"; 
$result = mysqli_query($query);


while($poll=mysqli_fetch_assoc($result)){
    echo "<tr>" .$poll['answer_title']. "</td>";
}

And here is my table:

+--------------+------------------+------+-----+---------+----------------+
| Field        | Type             | Null | Key | Default | Extra          |
+--------------+------------------+------+-----+---------+----------------+
| answer_id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| poll_id      | int(10) unsigned | NO   | MUL | 0       |                |
| answer_title | varchar(255)     | YES  |     | NULL    |                |
| votes_count  | int(10) unsigned | NO   |     | 0       |                |
| answer_order | smallint(6)      | NO   |     | 0       |                |
+--------------+------------------+------+-----+---------+----------------+

I cannot get to print anything but "Connection Successful"!

Can anyone tell me what is possibly wrong?

EDITED SQL to SQLI, still same problem

3 Answers 3

2

You are mixing mysql and mysqli

Change

$result = mysql_query($query);
while($poll=mysql_fetch_assoc($result)){

To

$result = mysqli_query($conn , $query);
while($poll=mysqli_fetch_assoc($result)){

Check Manual

Sign up to request clarification or add additional context in comments.

2 Comments

Did that, still nothing being displayed but connection successful!
Change $result = mysqli_query($query); to $result = mysqli_query($conn , $query);
2

You have to $conn that is connection class object to mysqli_query.

$result = mysqli_query($conn,$query);

1 Comment

Yes! it was conn first and then query, as Sadikhasan stated
0

It could be because you're using both mysql and mysqli functions. Also, mysql is being deprecated soon, you might want to switch to PDO statements, it's fairly easy to setup, here's a tutorial that you could apply fairly quickly Link

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.