Hello,
I wondered if anyone could offer some guidance, I trying to write a
php script to connect to a database, and display the records in a
table.
I found the code here in a php4 text, and when I run this directly
through the php intrupeter, the line Successfully connected is display
and 4 as the number of rows.
The database table we connect to, has three field username, firstname,
surname.
When I tried a while loop, to display the data in a table. No values
were displayed.
Could anyone possibly demonstrate how to display the username,
firstname, surname values in a basic table?
Thank you
<?php
function db_connect(){
global $MYSQL_ERRNO, $MYSQL_ERROR;
$link_id = mysql_connect("localhost","user04", "password04");
if(!$link_id){
$MYSQL_ERROR = "Connection failed";
return 0;
}
else if(empty($dbname) && !mysql_select_db("database04")){
$MYSQL_ERROR = mysql_error();
return 0;
} else return $link_id;
}
!$link_id = db_connect();
if(!$link_id) die(error_message('Error connecting'));
$result = mysql_query("SELECT * FROM users");
if(!$result) error_message('Error in selection');
else echo "Successfully connected. ";
$query_data = mysql_fetch_array($result);
$total_records = $query_data[0];
if(!$total_records) error_message('No records');
else echo "$total_records.";
?>