473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Display mySQL query with PHP on a webpage

Hi,

I have created a database on a website using phpmyadmin and I would like to display the result of a mySQL query on a webpage using PHP.

I used the following code and nothing appears on my webpage:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // mySQL database connection
  3.  
  4. $con = mysql_connect("db_server", "username", "password");
  5. if (!$con) 
  6. {
  7. die ('Could not connect: ' . mysql_error());
  8. }
  9.  
  10. mysql_select_db("db_name", $con);
  11.  
  12. $query = 'SELECT * FROM person';
  13.  
  14. $result = mysql_query($query);
  15.  
  16. while($row = mysql_fetch_assoc($result));
  17. {
  18. echo $row['name'];
  19. echo $row['surname'];
  20. echo $row['country'];
  21. }
  22. ?>
Can anyone help me fix this, please ?
Oct 27 '12 #1
3 3066
Luuk
1,047 Expert 1GB
Change "db_server" to "localhost" on line 4?

and change "db_name" to that databasename you created in phpmyadmin (line 10)
Oct 27 '12 #2
Well, I put db_name and username in the post because the host of the database is not localhost on the server where my site is hosted and for privacy . I found the solution though. I have to upgrade my account, my database is not remotely accessible
Oct 27 '12 #3
Luuk
1,047 Expert 1GB
hmm, is it not 'local' to where your PHP script is running?

If the script is running at 'example.com', and your database is also at 'example.com', than you should put 'localhost' in the servername...
Oct 27 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: joemyre | last post by:
Hi everyone, What I'm trying to do is take php variables i got from user input, and pass them as the MySQL query terms. $query = "select * from ident where ".$searchtype1."=".$searchterm1."";...
0
by: Murphy | last post by:
I am currently migrating a db from SQL Server & MySQL and ? (front end yet to be decided upon) As I familiarise myself with MySQL populating tables etc can be quite clumbersome. After reading the...
0
by: taras.di | last post by:
Hi everyone, I've come across an extremely strange problem. The exact same query in both mysql command line client, and mysql query browser gives entirely different results. I was hoping someone...
2
by: Jerry M. Gartner | last post by:
Greetings: As evident from a previous post, I am a php noob. I would like to display MySQL query results in an html table with one of the row values as a category and the rest of the data...
6
khalidbaloch
by: khalidbaloch | last post by:
i want to show on page the messege that say there is currently no item when a mysql query return no record instead of blank page .. i hope this is not a big issue and will be resolved in first reply...
2
by: Flic | last post by:
Hi, I have a basic db that I access with MySQL query browser. Everything seems fine to me but I am using this db as part of a php shopping basket and when I try to add an item I get: Notice:...
2
by: stmfc | last post by:
i have a problem with user creation for mysql db i think the problem stems from string style. GRANT ALL ON newDB.* TO 'test'@'localhost' IDENTIFIED BY 'test'; i am...
10
by: Lloyd Harold | last post by:
I'm very new to PHP and attempting to put together a simple script for retrieving MySQL data of personal records. The MySQL table I'm using consists of: 0: id 1: name 2: location (an integer...
1
by: pretzelboy | last post by:
Hi, I last wrote software 13years ago in the pascal, dbase, clipper days. I have recently built a Ubuntu Box and with C++ (and help from the web) setup a serial barcode reader program using Mysql...
5
by: lisles | last post by:
i have a page funtion.php which hs the function to connect to the db /* Mysql Connection */ function connect(){ global $db_server,$db_user,$db_pass,$db;//Global Values from the config.php...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.