Jump to content

Just learning and running into snags


taskhill

Recommended Posts

Hello everyone,

 

I am very new to php and have chosen to buy a book to learn this programming language.  I have however created a script that I can't seem to get to work and was looking for some assistance.  Since I probably will be spending a lot of time here I decided to post my first topic today.

 

Can someone please tell me what is wrong with this remedial script.  Everytime I try and access the page, it is returned completely blank.  The link for the page is http://www.riverglenpatrol.com/register1.php and the code is as follows:

 

<?php
//Script 8.9 - register1.php

//Address error handling
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE):

//Set the title of the page and require the header template
define ('TITLE', 'Register');
require ('header.html');

//Basic html formating stuff
print '<div id="leftcontent">
<h1>Registration Form</h1>
<p>Register so that you can take advantage of certain features like this, that, and the other thing.</p>';

//Check if the form has been submitted.
if (isset ($_POST['submit'])){

//Create a flag variable
$problem = FALSE;

//Check for each value
if (empty ($_POST['username'])){
	$problem = TRUE;
	print '<p>Please enter a username!</p>';
}

if (empty ($_POST['first_name'])){
	$problem = TRUE;
	print '<p>Please enter your first name!</p>';
}

if (empty ($_POST['last_name'])){
	$problem = TRUE;
	print '<p>Please enter your last name!</p>';
}

if (empty ($_POST['email'])){
	$problem = TRUE;
	print '<p>Please enter your email address!</p>';
}

if (empty ($_POST['password1'])){
	$problem = TRUE;
	print '<p>Please enter a password!</p>';
}

if ($_POST['password1'] != $_POST['password2']){
	$problem = TRUE;
	print '<p>Your password did not match the confirmed password!</p>';
}

if (!$problem){
	print '<p>You are now registered!<br />
	Okay, you are not really registered but...</p>';
	}else{
	print '<p>Please try again!</p>';
}
}

//Begin the html form

print '<form action="register1.php" method="post"><p>';

//Create a sticky username input:
print 'Username: <input type="text" name="username" size="30" value="' . $_POST['username'] . '" /><br />';

print 'First Name: <input type="text" name="first_name" size="30" value="' . $_POST['first_name'] . '" /><br />

Last Name: <input type="text" name="last_name" size="30" value="' . $_POST['last_name'] . '" /><br />

Email Address: <input type="text" name="email" size="30" value="' . $_POST['email'] . '" /><br />';

print 'Password: <input type="password" name="password1" size="20" /><br />
Confirm Password: <input type="password" name="password2" size="20" /><br />

<input type="submit" name="submit" value="Register!" /></p>

</form>';

print '</div>';

//add the footer page
require ('footer.html');

?>

 

Any and all help is greatly appreciated.

 

Thanks in advance

 

Task

 

Link to comment
https://forums.phpfreaks.com/topic/112843-just-learning-and-running-into-snags/
Share on other sites

All I can come up with is that your server is disallowing all error messages and, even though you are trying to turn them on, none are being displayed. Is the doctype that is in the generated source coming from the require("header.htm"); and require("footer.html"); lines? Or is that source different? Try removing those two and see if anything gets displayed.

When learning PHP, developing php code, or debugging php code, turn on full php error reporting (set error_reporting to E_ALL (php.ini) or the equivalent numeric value (.htaccess) and set display_errors = On) in the master php.ini or in a .htaccess file to get php to help you.

 

For the problem in this thread, a fatal parse error would have been generated. Turning on error reporting in the script has no effect in this case because the script is never executed.

 

Also, you should only modify error reporting in a script for debugging purposes and should not normally set error_reporting/display_errors in a script as that will override any global settings you put in the php.ini or .htaccess file.

 

Lastly, by eliminating E_NOTICE from the error_reporting setting, you are dooming your code to simple errors like typo's in variable names and turning off E_NOTICE messages on a live server will prevent the logging of errors generated by things like unexpected user input values (or hacking attempts) that you need to have a record of so that you can modify your code to validate or process correctly. Leave error_reporting set to E_ALL and only turn display_errors off on a live server to prevent the output of errors to the visitor but still log all errors.

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.