Jump to content

Am I On Crack? Can't get this to work


suttercain

Recommended Posts

Hi Everyone  ;D

 

I am trying to just display a simple list using PHP via MySQL. Nothing fancy, no css at this point just a list.

 

<?php
$username = "iiiii";
$password = "iiiiii";
$dbname = "iiiiii";
$hostname = "localghost"; 


// connect and select the database
$conn = mysql_connect($host, $user, $password) or die(mysql_error());
$db = mysql_select_db($dbName, $conn) or die(mysql_error());

//Make the Query
$query = "SELECT * FROM 1997data ORDER BY MFR";
$result = @mysql_query ($query)or die(mysql_error());//Run the Query

if ($result {//If it ran okay display the record

//Table header
echo '<table align="center" cellspacing="0" cellpadding ="5">
<tr><td align="left"><b>Manufacture</b></td></tr>
';

//Fetch and Print
while ($row = mysql_fetch_array (result, MYSQL_ASSOC)) {
echo '<tr><td align="left">' . $row['mfr'] . '</td></tr>
';
}

echo '</table>';

mysql_free_result ($result);//Free up resources

} else { //if it did not run okay
echo '<p>' . mysql_error() . '<br/><br/>Query; ' . $query . '</p>'; //Debugging
}

mysql_close(); //Close connection
?>

 

When I go to view the page, list.php, I don't get an error reports, just the white page. Blank. Nothingness.... the abyss.

 

Can someone tell me what I am doing wrong? Thanks in adavance!

 

 

Link to comment
https://forums.phpfreaks.com/topic/36781-am-i-on-crack-cant-get-this-to-work/
Share on other sites

Hi Jesirose,

 

Thanks for the reply. I made the change

 

if ($result){

 

But instead of the white "nothing" like from The Never Ending Story, I now get the following error...

 

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

 

I know it's right there in front of me, but I can't get it...

 

The login information is all correct. I changed it in the above code for security reasons.

 

My question is, how come the list isn't being displayed on the page. I am selecting it, identifying the table and sort order. But I get either the blank page or the error "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)"

 

I have done the list display in the past but I have been unable to achieve this over the past 2 days.

 

Shannon

check on this

//**the variable $dbname doesn't match with the $dbName

 

 

<?php

$username = "iiiii";

$password = "iiiiii";

 

//**the variable $dbname doesn't match with the $dbName below

$dbname = "iiiiii";

$hostname = "localghost";

 

 

// connect and select the database

$conn = mysql_connect($host, $user, $password) or die(mysql_error());

 

//$dbName doesn't match with the $dbname above

$db = mysql_select_db($dbName, $conn) or die(mysql_error());

 

//Make the Query

$query = "SELECT * FROM 1997data ORDER BY MFR";

$result = @mysql_query ($query)or die(mysql_error());//Run the Query

 

if ($result {//If it ran okay display the record

 

//Table header

echo '<table align="center" cellspacing="0" cellpadding ="5">

<tr><td align="left"><b>Manufacture</b></td></tr>

';

 

//Fetch and Print

while ($row = mysql_fetch_array (result, MYSQL_ASSOC)) {

echo '<tr><td align="left">' . $row['mfr'] . '</td></tr>

';

}

 

echo '</table>';

 

mysql_free_result ($result);//Free up resources

 

} else { //if it did not run okay

echo '<p>' . mysql_error() . '<br/><br/>Query; ' . $query . '</p>'; //Debugging

}

 

mysql_close(); //Close connection

?>

first problem i noticed with your sql

 

if ($result {//If it ran okay display the record

 

should be

if ($result) {//If it ran okay display the record

 

 

Second Problem

//Fetch and Print

while ($row = mysql_fetch_array (result, MYSQL_ASSOC)) {

 

Should be

while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.