$Three3 Posted December 9, 2009 Share Posted December 9, 2009 Hi, I have been stuck on this for a while now. I am really new to PHP and I cannot get the script below to display the html form. I have tried practically everything but it is just not working for me. It just displays a blank page. Any help is greatly appreciated. Also, ever since I have switched over to a new server, I have not been able to get any errors to display while testing my scripts. How can I go about getting the errors turned back on? Thanks <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>User Registration</title> </head> <body> <?php //Check to see if form has been submitted if (isset($_POST['submitted'])) { //Set Flag Varibale $problem = FALSE ; //There are currently no problems //Validate all forms if (empty($_POST['username'])) { $problem = TRUE ; die('You must enter a username') ; } if (strlen($_POST['usernmae'] <= 4)) { $problem = TRUE ; die('You must enter a username longer than 4 characters') ; } if (empty($_POST['email'])) { $problem = TRUE ; die('You must enter an email address.') ; } if (empty($_POST['password1'])) { $problem = TRUE ; die('You must enter a password') ; } if (strlen($_POST['password1'] <= 4)) { $problem = TRUE ; die('You must enter a password longer than 4 characters') ; } if ($_POST['password1'] != $_POST['password2']) { $problem = TRUE ; die('Your passwords do not match. Please go back and correct the issue.') ; } if (!$problem) { //If there were not any problems //Try to open the file to write to if ($fp = fopen('../userinfo/userinfo.txt' , 'ab')) { $data = $_POST['username'] . "<br />" . $_POST['email'] . "<br />" $_POST['password1'] . "\n" ; //Write to the file and Close the file fwrite($fp , $data) ; fclose($fp) ; echo "You have successfully registered! Your user information is below: (We have also emailed you this info) <br /><br /><br />" ; $to = $_POST['email'] ; $subject = 'User Registration Information' ; $body = $data ; //Mail the information to the user mail($to , $subject , $body , 'From: jon@gmail.com') ; } else { die('You could not register. There was a system error. Please try again.') ; } } else { die('You forgot a field. Please go back and fill out all forms.') ; } } else { echo '<form action="myregister.php" method="post"> <p>Username:* <input name="username" type="text" size="20" />Must be longer than 4 characters</p> <p>E-mail:* <input name="email" type="text" size="20" /></p> <p>Password:* <input name="password1" type="password" size="20" />Must be longer than 4 characters</p> <p>Confirm Pasword:* <input name="password2" type="password" size="20" /></p> <input name="submit" type="submit" value="Register" /> <input name="submitted" type="hidden" value="true" /> </form>' ; } echo "<p>The * denotes a required field</p>" ; //End PHP ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted December 9, 2009 Share Posted December 9, 2009 to turn on errors, add these lines to the top of you PHP scripts, immediately following the <?php: <?php ini_set ('display_errors', 1); error_reporting (E_ALL); see what errors come up and post them here. Quote Link to comment Share on other sites More sharing options...
$Three3 Posted December 9, 2009 Author Share Posted December 9, 2009 to turn on errors, add these lines to the top of you PHP scripts, immediately following the <?php: <?php ini_set ('display_errors', 1); error_reporting (E_ALL); see what errors come up and post them here. Okay I just added that to the top but it still gives me a blank page. I even tried it on the little script below but it still does not display any errors. <?php ini_set ('display_errors', 1); error_reporting (E_ALL); for ($i = 1 ; $i <= 10 ; $i++) { echo $i ?> Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted December 9, 2009 Share Posted December 9, 2009 <?php //Try to open the file to write to if ($fp = fopen('../userinfo/userinfo.txt' , 'ab')) { //this line gives a parse error because you have incorrectly concatenated "<br />" to $_POST['password1'] .. you're missing a . $data = $_POST['username'] . "<br />" . $_POST['email'] . "<br />" $_POST['password1'] . "\n" ; change that to: <?php //Try to open the file to write to if ($fp = fopen('../userinfo/userinfo.txt' , 'ab')) { $data = $_POST['username'] . "<br />" . $_POST['email'] . "<br />" . $_POST['password1'] . "\n" ; remove the opening <?php of course. but that will work now. Quote Link to comment Share on other sites More sharing options...
$Three3 Posted December 9, 2009 Author Share Posted December 9, 2009 <?php //Try to open the file to write to if ($fp = fopen('../userinfo/userinfo.txt' , 'ab')) { //this line gives a parse error because you have incorrectly concatenated "<br />" to $_POST['password1'] .. you're missing a . $data = $_POST['username'] . "<br />" . $_POST['email'] . "<br />" $_POST['password1'] . "\n" ; change that to: <?php //Try to open the file to write to if ($fp = fopen('../userinfo/userinfo.txt' , 'ab')) { $data = $_POST['username'] . "<br />" . $_POST['email'] . "<br />" . $_POST['password1'] . "\n" ; remove the opening <?php of course. but that will work now. Lol wow. A couple of days for a missing period. Thanks a lot man! Lol. If you do not mind also, is there anyway to get an error on something like this? Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted December 10, 2009 Share Posted December 10, 2009 LAST EDIT: if my memory serves me correct, i don't believe enabling error_reporting at runtime will display parse errors since the server parses the file before it executes any code, and ini_set() & error_reporting() being code, will not be parsed, therefore, reporting will not be set. if you have access to your php.ini file, you will have to set the appropriate values in there. ----- check to make sure that your web server has "write" permissions to it's default logging directory (or the logging directory specified in your php.ini file) EDIT: will be this line in php.ini file: error_log = c:/path/to/php_error.log make sure that the directory (and file itself) have write permissions. NOTE: each log file is also assigned an allotted size as well, meaning that it can fill up, and if full will not be writable anymore, also causing errors not to show. just something in case anybody was wondering. hope this helps since knowing what errors are occurring is a HUGE help/time(sanity)-saver in development. Quote Link to comment 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.