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
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...

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

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)) {

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.