Jump to content

Recommended Posts

New to PHP and MySQL so hopefully someone can help with what's probably a simple fault due to my lack of knowledge.

 

When I run the following script I get a message that Apache HTTP Server has encountered a problem and needs to close We are sorry for the inconvenience. Please tel Microsoft about this problem Send error report or Don't send blah blah etc.  (I'm sure we've all seen this report.

 

If I remove the line msql_close() the script runs as expected!!

 

Thanks in advance

 

Here's the script

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

 

<html lang="en" xml:lang="en">

<head>

<?php

include("dbinfo.inc.php");

 

mysql_connect("localhost",$username,$password);

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

$query="SELECT * FROM contacts";

$result=mysql_query($query);

 

$num=mysql_numrows($result);

 

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

?>

<table border="0" cellspacing="2" cellpadding="2">

<tr>

<th><font face="Arial, Helvetica, sans-serif">Name</font></th>

<th><font face="Arial, Helvetica, sans-serif">Phone</font></th>

<th><font face="Arial, Helvetica, sans-serif">Mobile</font></th>

<th><font face="Arial, Helvetica, sans-serif">Fax</font></th>

<th><font face="Arial, Helvetica, sans-serif">E-mail</font></th>

<th><font face="Arial, Helvetica, sans-serif">Website</font></th>

</tr>

 

<?php

$i=0;

while ($i < $num) {

$first=mysql_result($result,$i,"first");

$last=mysql_result($result,$i,"last");

$phone=mysql_result($result,$i,"phone");

$mobile=mysql_result($result,$i,"mobile");

$fax=mysql_result($result,$i,"fax");

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

$web=mysql_result($result,$i,"web");

 

?>

<tr>

<td><font face="Arial, Helvetica, sans-serif"><?php echo "$first $last"; ?></font></td>

<td><font face="Arial, Helvetica, sans-serif"><?php echo "$phone"; ?></font></td>

<td><font face="Arial, Helvetica, sans-serif"><?php echo "$mobile"; ?></font></td>

<td><font face="Arial, Helvetica, sans-serif"><?php echo "$fax"; ?></font></td>

<td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<?php echo "$email"; ?>">E-mail</a></font></td>

<td><font face="Arial, Helvetica, sans-serif"><a href="<?php echo "$web"; ?>">Website</a></font></td>

</tr>

<?php

++$i;

}

 

mysql_close();

?>

 

Link to comment
https://forums.phpfreaks.com/topic/219456-new-to-php-mysql/
Share on other sites

I just saw a bug report that seems to be related to this. Try a couple of changes and see if it cures the problem

 

Assign the connection to a variable:

$conn = mysql_connect("localhost",$username,$password);

 

Then close the specific connection:

mysql_close($conn);

Link to comment
https://forums.phpfreaks.com/topic/219456-new-to-php-mysql/#findComment-1138002
Share on other sites

I just saw a bug report that seems to be related to this. Try a couple of changes and see if it cures the problem

 

Assign the connection to a variable:

$conn = mysql_connect("localhost",$username,$password);

 

Then close the specific connection:

mysql_close($conn);

 

Yeah, it's probably the bug in PHP 5.3.0 that caused PHP to crash when you mysql_close() when there's no handle given.

Link to comment
https://forums.phpfreaks.com/topic/219456-new-to-php-mysql/#findComment-1138282
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.