PHP Displaying output from mysql

Hi All I am a newbie and would appreciate any help you can give me.

I am using XAMPP on my mac to develop my 1st php/mysql site.

I have a db called localshops2u, and a table within that called users_shops, within that I have a column called SHOP_ID (There is more but for the purposes of getting this working I just want to output this - to prove I can get it working)

With this code I get no output at all:

<?php $host = "localhost"; $user = "root"; $password = ""; $database ="localshops2u"; $connection = mysql_connect($host,$user,$password) or die ("Server connection not made"); $db = mysql_select_db($database,$connection) or die ("db connection not made"); $query = "SELECT * FROM USERS_SHOPS"; $result = mysql_query($query,$connection) or die ("cannot query USERS_SHOPS table"); while ($row = mysql_fetch_array($result)) { echo $row['SHOP_ID'] } ?>

any advice (novice error?)

Hi,

Replace these parts…
[php]
$query = “SELECT * FROM USERS_SHOPS”;
$result = mysql_query($query,$connection) or die (“cannot query USERS_SHOPS table”);
[/php]
with

[php]
$query = "SELECT * FROM USERS_SHOPS";
$result = mysql_query($query) ;
if(!result){
echo “cannot query USERS_SHOPS table”;
}
[/php]

that should work

i recommand to change all the mysql_ functions to mysqli_ functions since they will not work anymore in near future versions of php

I didnt know this thanks for the heads up

mysql_* functions have been deprecated but not yet removed. EVERYONE here should use mysqli or PDO in all future development. Prepared statements are a huge step forward in security (SQL injection).

Sponsor our Newsletter | Privacy Policy | Terms of Service