Page 1 of 1

PHP Mysql error

Posted: Thu Apr 15, 2010 9:12 am
by bcart
Hi there

I'm not sure if this is a PHP or MySQL problem. I am currently running an exam booking system which at the checkout emails the booking administrator the details of the exams that have been booked.

If 1 person completes this then the system works perfectly however if more than 1 person tries to complete the booking at the same time then the email is not sent, it comes up with the following error message;
Warning: mail() [function.mail]: Failed to Receive in prog_admin\view_booking.php on line 88
Line 88 reads...

Code: Select all

mail($to, $subject, $body, $headers);
The data gets stored into a mysql database which again works perfectly even when multiple users are booking exams however I get an error message saying....
Could not connect to MySQL: Can't connect to MySQL server on 'localhost' (10056)
I'm assuming it's got something to do with the number of connections being opened up with the database at 1 time. Does anyone know how to solve the problem?

Any help would be much appreciated.

Cheers!

Re: PHP Mysql error

Posted: Thu Apr 15, 2010 10:02 am
by Technocrat
Your first error probably means that your server's mail function isn't setup correctly. Most like the SMTP in the php.ini isn't correct.

Your second error means exactly what it says. It cannot connect to the mysql server on that box. Could be a number of reasons for it. Generally the username and password is not correct.

Re: PHP Mysql error

Posted: Thu Apr 15, 2010 10:08 am
by bcart
Technocrat wrote:Your first error probably means that your server's mail function isn't setup correctly. Most like the SMTP in the php.ini isn't correct.

Your second error means exactly what it says. It cannot connect to the mysql server on that box. Could be a number of reasons for it. Generally the username and password is not correct.
What I don't understand is that it's fine when 1 person does it but when there are 2 or more users then the errors occur. The username and password must be correct because when 1 user completes it then there are no errors!

Any ideas?

Re: PHP Mysql error

Posted: Thu Apr 15, 2010 10:49 am
by bcart
My actual script is this

Code: Select all

<?php

ob_start();

session_start();

//Declare the includes
include ('../includes/main.php');
include ('../Connections/mysqli_connect.php');

$ta = $_SESSION['ta_name'];
$ref = $_SESSION['ref'];
$email = $_SESSION['email'];

//Exam Detail Query
$order_query = "SELECT * FROM exam_details WHERE ref='$ref' ";

//Run the query
$result_order_query = @mysqli_query ($dbc, $order_query);
$row = @mysqli_fetch_array ($result_order_query);
$records = $row[0];
$number = mysqli_num_rows($result_order_query);

$learner = $row ['learner'];

//Learner Query
$learner_query = "SELECT * FROM exam_learner_details WHERE id='$learner' ";

//Run the query
$result_Learner = @mysqli_query ($dbc, $learner_query);
$row_learner = @mysqli_fetch_array ($result_Learner);
$records_learner = $row_learner[0];

$i=1;

$body = '<h1>Review of Exam Booking</h1>';

do {
	
	//Exam Group / Title Query
	$exam_group = $row['exam_group'];
	$q_group = "SELECT exam_group FROM exam_group WHERE id='$exam_group'";
	$r_group = mysqli_query($dbc, $q_group);
	$row_group = mysqli_fetch_array($r_group);
	
	$exam_title = $row['title'];
	$q_title = "SELECT title FROM exam_title WHERE id='$exam_title'";
	$r_title = mysqli_query($dbc, $q_title);
	$row_title = mysqli_fetch_array($r_title);
	
	//Make the body of the email
	$body .= '
	<h2>' . $row_learner['fname'] . ' ' . $row_learner['sname'] . '</h2>
	<strong>Exam ' . $i . '</strong><br /><br />
	<strong>Exam Date: </strong>' . $row['exam_date'] . '<br />
	<strong>Exam Time: </strong>' . $row['exam_time'] . '<br />
	<strong>Exam Group: </strong>' . $row_group['exam_group'] . '<br />
	<strong>Exam Title: </strong>' . $row_title['title'] . '<br />
	<strong>Invigilator: </strong>' . $row['invigilator'] . '<br />
	<strong>Method: </strong>' . $row['method'] . '<br />
	<strong>Location: </strong>' . $row['location'] . '<br />
	<strong>Training Required: </strong>' . $row['training_req'] . '<br />
	<strong>Additional Information: </strong>' . $row['comments'] . '<br />
	<br /><br />';
	
	$i++;
		
} while ($row = @mysqli_fetch_array ($result_order_query)); //end of do...while loop
	
?>
   
    </div><!--end of left -->
    
    <div id="content">
    
    <?php
	
	if (isset($_POST['submitted'])) {
		
		$to = 'bcart@totalpeople.co.uk';
		//$to = 'exambookings@totalpeople.co.uk' . ', ' . 'bcart@totalpeople.co.uk';
		//$to = 'exambookings@totalpeople.co.uk' . ', ' . $email;
		$subject = 'Exam Booking';
		$headers  = "From: $email\r\n";
		$headers .= "Content-type: text/html\r\n";
	
		// Send the email:
		mail($to, $subject, $body, $headers);
		
		// Print a message:
		echo '<h1>Thank you</h1>
		
		<h2>Confirmation</h2>
		
		<p>Your request has been submitted successfully and will be dealt with as soon as possible. You will only be contacted if there appears to be a query with your booking.  </p>
		
		<p>In the meantime if you have any queries or need to make a cancellation please contact either:</p> 
		
		<ul>
			<li>Becky Marks (Key Skills Examinations Officer) 01606 734031</li>
			<li>Ellie Georgieva (Programme Administrator) 01606 734029</li>
		</ul>
		
		<br />
		
		<p>To book another learner onto an exam <a href="add_learner.php">click here</a>.</p>
		
		<p>All guidance you may require before and during the exam together with the exam bookings procedure can be found on the intranet under Programme Administration.</p>';
		
	} else {
	
	echo $body;
	
	echo '
	<form action="view_booking.php" method="post" name="form" id="form">
	
	<p>To confirm your booking please click the \'Confirm Booking\' button below.</p>
	
	<table border="0" cellspacing="0" cellpadding="5">
  	<tr>
    <td><input name="submit" type="submit" value="Confirm Booking"/></td>
    </tr>
	</table>
	<input name="submitted" type="hidden" value="TRUE" />
	
</form>';
	
	}
	
	?>
    
    </div><!--end of content -->
	
    <div id="right">
        
        <?php

			include ('includes/second_menu.php');

		?>
        
        <br /><br />
        
<?php

include ('../includes/footer.php');

?>
I have also come across the error message...
Warning: mail() [function.mail]: SMTP server response: 503 Bad command sequence in prog_admin\view_booking.php on line 88
Again this only happens when multiple users are booking people onto exams. With only 1 user it's working perfectly! :banghead:

Any ideas? I'm at a total loss!!!

Re: PHP Mysql error

Posted: Thu Apr 15, 2010 2:33 pm
by mikosiko
what are the values of:

- Max Connections and
- Max Connections per User

in your mysql config?

Re: PHP Mysql error

Posted: Fri Apr 16, 2010 6:29 am
by bcart
mikosiko wrote:what are the values of:

- Max Connections and
- Max Connections per User

in your mysql config?
Max Connections = -1
Max Connections per User = -1

Thanks

Re: PHP Mysql error

Posted: Fri Apr 16, 2010 8:53 am
by mikosiko
I could be wrong... but according to Mysql Manual both values need to be >= 0... in fact, for Max Connection is defined with a range of 1-16384 and Max Conn per User as 0-4294967295... in both cases beeing 0 allowed to definite no limits. I don't know the effect to define them as negative values.

http://dev.mysql.com/doc/refman/5.1/en/ ... onnections
http://dev.mysql.com/doc/refman/5.0/en/ ... onnections

I'm referencing latest MySql version... didn't look previous versions (which can be your case)

Miko

Re: PHP Mysql error

Posted: Fri Apr 16, 2010 9:51 am
by bcart
mikosiko wrote:I could be wrong... but according to Mysql Manual both values need to be >= 0... in fact, for Max Connection is defined with a range of 1-16384 and Max Conn per User as 0-4294967295... in both cases beeing 0 allowed to definite no limits. I don't know the effect to define them as negative values.

http://dev.mysql.com/doc/refman/5.1/en/ ... onnections
http://dev.mysql.com/doc/refman/5.0/en/ ... onnections

I'm referencing latest MySql version... didn't look previous versions (which can be your case)

Miko
Must have been having a moment! I was looking in the php.ini file! D'oh!!!!

Anyway the real settings are as follows

Max Connections and = 151
Max Connections per User = 0

Cheers