Jump to content

I created display.php to show records from a mysql database on my site but?


xx_britt

Recommended Posts

I don't know what to do now?

 

I was told that if I wanted to display records from a mysql database on my site I would have to create a file named display.php and code it which I did... but now have no idea how to get it to display on my site?

 

What do I put in default.html?

I of course change the variables to match my database name and user and password but this is the code:

 

<?

$username="username";

$password="password";

$database="database";

 

mysql_connect(localhost,$db_user,$password);

@mysql_select_db($db_name) or die( "Unable to select database");

$query="SELECT * FROM contacts";

$result=mysql_query($query);

 

$num=mysql_numrows($result);

 

mysql_close();

 

echo "<b><center>Database Output</center></b><br><br>";

 

$i=0;

while ($i < $num) {

 

$Name=mysql_result($result,$i,"name");

$Email=mysql_result($result,$i,"email");

$Comments=mysql_result($result,$i,"comments");

 

echo "<b>$name $email</b><br>Comments: $comments<br><hr><br>";

 

$i++;

}

 

?>

I of course change the variables to match my database name and user and password but this is the code:

 

<?

$username="username";

$password="password";

$database="database";

 

mysql_connect(localhost,$db_user,$password);

@mysql_select_db($db_name) or die( "Unable to select database");

$query="SELECT * FROM contacts";

$result=mysql_query($query);

 

$num=mysql_numrows($result);

 

mysql_close();

 

echo "<b><center>Database Output</center></b><br><br>";

 

$i=0;

while ($i < $num) {

 

$Name=mysql_result($result,$i,"name");

$Email=mysql_result($result,$i,"email");

$Comments=mysql_result($result,$i,"comments");

 

echo "<b>$name $email</b><br>Comments: $comments<br><hr><br>";

 

$i++;

}

 

?>

 

try this:

 

while ($row = mysql_fetch_assoc($result)) {

$name=$row['name'];
$email = $row['email'];
$comments= $row['comments'];

echo "<b>$name $email</b><br>Comments: $comments<br><hr><br>";

}

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.