dambuster Posted November 22, 2010 Share Posted November 22, 2010 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/219456-new-to-php-mysql/ Share on other sites More sharing options...
Pikachu2000 Posted November 22, 2010 Share Posted November 22, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/219456-new-to-php-mysql/#findComment-1138002 Share on other sites More sharing options...
TheEvilMonkeyMan Posted November 23, 2010 Share Posted November 23, 2010 Are you sure the connection is open when you close it? See if adding a conditional statement helps your server crashing problem if($conn) { mysql_close($conn); } Otherwise you might want to try reinstalling Apache and/or MySQL. Quote Link to comment https://forums.phpfreaks.com/topic/219456-new-to-php-mysql/#findComment-1138281 Share on other sites More sharing options...
TheEvilMonkeyMan Posted November 23, 2010 Share Posted November 23, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/219456-new-to-php-mysql/#findComment-1138282 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.