Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8913965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:35:56+00:00 2026-06-15T04:35:56+00:00

I want to retrieve data from a database with PHP and show it on

  • 0

I want to retrieve data from a database with PHP and show it on a website.

This code does not work correctly. I want to display all cars that are Chevy on my database.

<?php
$db = mysqli_connect("localhost","myusername",
"mypassword","database");

if (mysqli_connect_errno()) { 
    echo("Could not connect" .
      mysqli_connect_error($db) . "</p>");
    exit(" ");
}

$result = mysqli_query($query);

if(!$result){
  echo "<p> Could not retrieve at this time, please come back soon</p>" .   
    mysqli_error($dv);
}

$data = mysql_query("SELECT * FROM cars where carType = 'Chevy' AND active = 1")
  or die(mysql_error());

echo"<table border cellpadding=3>";
while($row= mysql_fetch_array( $data ))
{
  echo"<tr>";
  echo"<th>Name:</th> <td>".$row['name'] . "</td> ";
  echo"<th>ImagePath:</th> <td>".$row['imagePath'] . " </td></tr>";
  echo"<th>Description:</th> <td>".$row['description'] . "</td> ";
  echo"<th>Price:</th> <td>".$row['Price'] . " </td></tr>";
}
echo"</table>";
?>

How do I get data from the database with PHP?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:35:58+00:00Added an answer on June 15, 2026 at 4:35 am

    you are not querying to database so it wont give you result

    this is how it works

    1. connect to the database by mysql_connect()

      mysql_connect("localhost", "username", "password") or die(mysql_error());

    2. than select the database like mysql_select_db()

      mysql_select_db("Database_Name") or die(mysql_error());

    3. you need to use mysql_query()

    like

     $query = "SELECT * FROM cars where carType = 'chevy' AND active = 1";
     $result =mysql_query($query); //you can also use here or die(mysql_error()); 
    

    to see if error

    1. and than mysql_fetch_array()

      if($result){
      while($row= mysql_fetch_array( $result )) {
      //result
      }
      }

    so try

    $data = mysql_query("SELECT * FROM cars where carType = 'chevy' AND active = 1")  or die(mysql_error()); 
     echo"<table border cellpadding=3>"; 
     while($row= mysql_fetch_array( $data )) 
     { 
        echo"<tr>"; 
        echo"<th>Name:</th> <td>".$row['name'] . "</td> "; 
        echo"<th>ImagePath:</th> <td>".$row['imagePath'] . " </td></tr>"; 
        echo"<th>Description:</th> <td>".$row['description'] . "</td> "; 
        echo"<th>Price:</th> <td>".$row['Price'] . " </td></tr>"; 
     } 
     echo"</table>"; 
     ?> 
    

    **Note:**

    `Mysql_*` function are deprecated so use `PDO` or `MySQLi` instead . I would suggest PDO its lot more easier and simple to read you can learn here [PDO Tutorial for MySQL Developers][5] also check [Pdo for beginners ( why ? and how ?)][6]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I retrieve data from a mysql database. I want to make this data available
I have DropDownList with CascadingDropDown extender. If I want to retrieve data from the
I want to display the data retrieved from the JSP page in my List.
I want applications to share certain database data. I want one application to retrieve
I'm trying to retrieve data from a POST method, code as follows: -(void)postXMLFeed:(NSString *)XMLStrPost
I am trying to fetch data from my database and when I display it
I am trying to retrieve data with JSON from my database and parse them
I have MySQL database server I need to update and retrieve data to/from MySQL
i am doing some practice on the codeigniter to retrieve the data from database
I am making a php page that retrieves data from a database table and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.