Jump to content
Larry Ullman's Book Forums

Registration Page


Recommended Posts

Hello Larry.

I need little help on registration page 80. I am getting this error when I uploaded to my site, but it looks fine and working on localhost. Also I am not getting an email that there is an errors on this page . Please help me. Thanks

 

An error occurred in script '/home3/citi/public_html/test/includes/reg.php' on line 155:

You could not be registered due to a system error. We apologize for any inconvenience.

Array

(

[0] => Array

(

[function] => my_error_handler

[args] => Array

(

[0] => 1024

[1] => You could not be registered due to a system error. We apologize for any inconvenience.

[2] => /home3/citi/public_html/test/includes/reg.php

[3] => 155

[4] => Array

(

[GLOBALS] => Array

*RECURSION*

[_POST] => Array

(

[first_name] => test

[last_name] => hello

[username] => testings

=> test@example.com

[pass1] => Hihi123

[pass2] => Hihi123

[category] => 3

[title] => test

[description] => test

[submit_button] => Next →

 

)

[_GET] => Array

(

)

[_COOKIE] => Array

(

[__utma] => 8882487.567969204.1322294083.1322294083.1322294083.1

[__utmz] => 8882487.1322294083.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)

)

[_FILES] => Array

(

)

[_SERVER] => Array

(

[CONTENT_LENGTH] => 168

[CONTENT_TYPE] => application/x-www-form-urlencoded

[DOCUMENT_ROOT] => /home3/citi/public_html/

[GATEWAY_INTERFACE] => CGI/1.1

[HTTP_ACCEPT] => image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, */*

[HTTP_ACCEPT_ENCODING] => gzip, deflate

[HTTP_ACCEPT_LANGUAGE] => en-us

[HTTP_CACHE_CONTROL] => no-cache

[HTTP_CONNECTION] => keep-alive

[HTTP_COOKIE] => __utma=8882487.567969204.1322294083.1322294083.1322294083.1; __utmz=8882487.1322294083.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=129758494.1909320003.1322984088.1322984088.1324242202.2; __utmz=129758494.1322984088.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)

 

[HTTP_USER_AGENT] => Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)

[HTTP_X_VIA] => Harmony proxy

[PATH] => /bin:/usr/bin

[QUERY_STRING] =>

[REDIRECT_STATUS] => 200

 

The Localhost looks fine .

Thanks!

 

Thank you for registering! To complete the process, please now click the below link to login the site

Click Next

An error occurred in script 'C:\xampp\htdocs\server\content\includes\reg.php' on line 139:

mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

 

Array

 

(

 

[0] => Array

 

(

 

[function] => my_error_handler

 

[args] => Array

 

(

 

[0] => 2

 

[1] => mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

 

[2] => C:\xampp\htdocs\server\content\includes\reg.php

 

 

 

 

Thanks

Link to comment
Share on other sites

I don't have a copy of this book and you haven't posted any of the relevant code so it's difficult to say for sure. Looking at the code from the downloads section I suspect that's coming from the else clause of:

 

if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.

 

This means that your database INSERT query is failing - possible causes:

  1. Database user doesn't have INSERT privileges
  2. Table structures does not match that at localhost causing a syntax error

In the else clause where you have:

 

trigger_error('You could not be registered due to a system error. We apologize for any inconvenience.');

 

Add a call to:

 

echo mysqli_error($dbc);

 

This will return more information about your specific database error.

  • Upvote 1
Link to comment
Share on other sites

i use the same code registration.php in a free domain butit doesnt send e-mail back why?

 

<?php

// This is the registration page for the site.

// This file both displays and processes the registration form.

// This script is begun in Chapter 4.

// Require the configuration before any PHP code as the configuration controls error reporting:

require ('./includes/config.inc.php');

// The config file also starts the session.

// Include the header file:

$page_title = 'Register';

include ('./includes/header.html');

// Require the database connection:

require ('./includes/mysql.inc.php');

// For storing registration errors:

$reg_errors = array();

// Check for a form submission:

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

// Check for a first name:

if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $_POST['first_name'])) {

$fn = mysqli_real_escape_string ($dbc, $_POST['first_name']);

} else {

$reg_errors['first_name'] = 'Please enter your first name!';

}

 

// Check for a last name:

if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $_POST['last_name'])) {

$ln = mysqli_real_escape_string ($dbc, $_POST['last_name']);

} else {

$reg_errors['last_name'] = 'Please enter your last name!';

}

 

// Check for a username:

if (preg_match ('/^[A-Z0-9]{2,30}$/i', $_POST['username'])) {

$u = mysqli_real_escape_string ($dbc, $_POST['username']);

} else {

$reg_errors['username'] = 'Please enter a desired name!';

}

 

// Check for an email address:

if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {

$e = mysqli_real_escape_string ($dbc, $_POST['email']);

} else {

$reg_errors['email'] = 'Please enter a valid email address!';

}

// Check for a password and match against the confirmed password:

if (preg_match ('/^(\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*){6,20}$/', $_POST['pass1']) ) {

if ($_POST['pass1'] == $_POST['pass2']) {

$p = mysqli_real_escape_string ($dbc, $_POST['pass1']);

} else {

$reg_errors['pass2'] = 'Your password did not match the confirmed password!';

}

} else {

$reg_errors['pass1'] = 'Please enter a valid password!';

}

 

if (empty($reg_errors)) { // If everything's OK...

// Make sure the email address and username are available:

$q = "SELECT email, username FROM users WHERE email='$e' OR username='$u'";

$r = mysqli_query ($dbc, $q);

 

// Get the number of rows returned:

$rows = mysqli_num_rows($r);

 

if ($rows == 0) { // No problems!

 

// Add the user to the database...

 

// Temporary: set expiration to a month!

// Change after adding PayPal!

//$q = "INSERT INTO users (username, email, pass, first_name, last_name, date_expires) VALUES ('$u', '$e', '" . get_password_hash($p) . "', '$fn', '$ln', ADDDATE(NOW(), INTERVAL 1 MONTH) )";

 

// New query, updated in Chapter 6 for PayPal integration:

// Sets expiration to yesterday:

$q = "INSERT INTO users (username, email, pass, first_name, last_name, date_expires) VALUES ('$u', '$e', '" . get_password_hash($p) . "', '$fn', '$ln', SUBDATE(NOW(), INTERVAL 1 DAY) )";

 

$r = mysqli_query ($dbc, $q);

if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.

 

// Get the user ID:

// Store the new user ID in the session:

// Added in Chapter 6:

$uid = mysqli_insert_id($dbc);

// $_SESSION['reg_user_id'] = $uid;

 

// Display a thanks message:

 

// Original message from Chapter 4:

//echo '<h3>Thanks!</h3><p>Thank you for registering! You may now log in and access the site\'s content.</p>';

 

// Updated message from Chapter 6:

echo "<h3>Thanks!</h3><p>Thank you for registering! To complete the process, please now click the button below so that you may pay for your site access via PayPal. The cost is $10 (US) per year.</p>";

// PayPal link added in Chapter 6:

echo '<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">

<input type="hidden" name="cmd" value="_s-xclick">

<input type="hidden" name="custom" value="' . $uid . '">

<input type="hidden" name="email" value="' . $e . '">

<input type="hidden" name="hosted_button_id" value="8YW8FZDELF296">

<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">

<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">

</form>

';

 

// Send a separate email?

$body = "Thank you for registering at <whatever site>. Blah. Blah. Blah.\n\n";

mail($_POST['email'], 'Registration Confirmation', $body, 'From: northherner@hotmail.com');

 

// Finish the page:

include ('./includes/footer.html'); // Include the HTML footer.

exit(); // Stop the page.

 

} else { // If it did not run OK.

trigger_error('You could not be registered due to a system error. We apologize for any inconvenience.');

}

 

} else { // The email address or username is not available.

 

if ($rows == 2) { // Both are taken.

 

$reg_errors['email'] = 'This email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.';

$reg_errors['username'] = 'This username has already been registered. Please try another.';

} else { // One or both may be taken.

// Get row:

$row = mysqli_fetch_array($r, MYSQLI_NUM);

 

if( ($row[0] == $_POST['email']) && ($row[1] == $_POST['username'])) { // Both match.

$reg_errors['email'] = 'This email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.';

$reg_errors['username'] = 'This username has already been registered with this email address. If you have forgotten your password, use the link at right to have your password sent to you.';

} elseif ($row[0] == $_POST['email']) { // Email match.

$reg_errors['email'] = 'This email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.';

} elseif ($row[1] == $_POST['username']) { // Username match.

$reg_errors['username'] = 'This username has already been registered. Please try another.';

}

 

} // End of $rows == 2 ELSE.

 

} // End of $rows == 0 IF.

 

} // End of empty($reg_errors) IF.

} // End of the main form submission conditional.<p>// Need the form functions script, which defines create_form_input():

require ('./includes/form_functions.inc.php');

?><h3>Register</h3>

<p>Access to the site's content is available to registered users at a cost of $10.00 (US) per year. Use the form below to begin the registration process. <strong>Note: All fields are required.</strong> After completing this form, you'll be presented with the opportunity to securely pay for your yearly subscription via <a href="

Link to comment
Share on other sites

<pre class="prettyprint">

I added

</pre>

<pre class="prettyprint">

<span class="pln"><font color="#000000">echo mysqli_error</font></span><span class="pun"><font color="#666600">(</font></span><span class="pln"><font color="#000000">$dbc</font></span><span class="pun"><font color="#666600">);</font></span></pre>

<p><span class="pun"><font color="#666600">after </font></span></p>

<pre class="prettyprint">

<span class="pun"><font color="#666600"><span class="pln"><font color="#000000">trigger_error</font></span><span class="pun"><font color="#666600">(</font></span><span class="str"><font color="#008800">'You could not be registered due to a system error. We apologize for any inconvenience.'</font></span><span class="pun"><font color="#666600">);</font></span></font></span></pre>

<p> </p>

<p><span class="pun"><font color="#666600">It's working now and Thanks very much for the help.</font></span></p>

<p> </p>

<p> </p>

<p> </p>

<p> </p>

<p><br />

 </p>

 

Link to comment
Share on other sites

I added

echo mysqli_error($dbc);

after

trigger_error('You could not be registered due to a system error. We apologize for any inconvenience.');

 

and it's working now. Thanks for the help.

Link to comment
Share on other sites

  • 2 weeks later...

 

Thanks again.

 

I added the redirect page after

 

$r = mysqli_query ($dbc, $q);

 

if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.

 

 

 

header('Location: http://www.citidesigners.com');

 

 

and I am getting this error.

 

 

An error occurred in script '/home3/citide/public_html/reg.php' on line 115:

Cannot modify header information - headers already sent by (output started at /home3/citide/public_html/reg.php:7)

 

Array

(

[0] => Array

(

[function] => my_error_handler

[args] => Array

(

[0] => 2

[1] => Cannot modify header information - headers already sent by (output started at /home3/citide/public_html/reg.php:7)

 

 

please help.

 

Thanks

Link to comment
Share on other sites

 Share

×
×
  • Create New...