Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

problem with a php form


  • Please log in to reply

#1
Dragon

Dragon

    All Around Computer Nut

  • Retired Staff
  • 2,682 posts
ok, i have torn this code apart over and over again. there must be somthing i'm missing, in the html editor's preview window it comes out perfectly, however when I actually load the file up in Firefox i get a totally different response.

here is the code
<body>
<?php # Script 3.13 - register.php
$page_title = 'Register';
include ('./includes/header.html');
if (isset($_POST['submitted'])) {
$errors = array();
if (empty($_POST['name'])) {
$errors[] = 'You forgot to enter your name.';
}
if (empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email address.';
}
if (!empty($_POST['password1'])) {
if ($_POST['password1'] != $_POST ['password2']) {
$errors[] = 'Your password did not match the confirmed password.';
}
} else {
$errors[] = 'You forgot to enter your password.';
}
if (empty($errors)) {
$body = "Thank you for registering with our site!\nYour password is '{$_POST['password1']}'. \n\nSincerely,\nUs";
mail ($_POST['email'], 'Thank you for registering!', $body, 'From: [email protected]');
echo '<h1 id="mainhead">Thank you!</h1>
<p>You are now registered. An email has been sent to your email address confirming the information.</p><p><br /></p>';
} else {
echo '<h1 id="mainhead">Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) {
echo " - $msg<br />\n";
}
echo '</p><p>Please go back and try again.</p><p><br /></p>';
}
}else {
?>
<h2>Register</h2>
<form action="register.php" method="post">
  <p>Name: <input name="name" size="20"
 maxlength="40" type="text"></p>
  <p>Email Address: <input name="email" size="20"
 maxlength="40" type="text"> </p>
  <p>Password: <input name="password1" size="10"
 maxlength="20" type="password"></p>
  <p>Confirm Password: <input name="password2"
 size="10" maxlength="20" type="password"></p>
  <p><input name="submit" value="Register"
 type="submit"></p>
  <input name="submitted" value="TRUE" type="hidden">
</form>
<?php }
include ('./includes/footer.html');
?>
and here is a screen shot of what it looks like in my FF browser, Until i get this resolved I can't check the the database connectivity end of it.

Attached Thumbnails

  • scr3.png

Edited by Dragon, 04 December 2005 - 09:43 PM.

  • 0

Advertisements


#2
Canoeingkidd

Canoeingkidd

    Malware Expert

  • Retired Staff
  • 148 posts
At the top you have two php opening tags...
<?php <?php # Script 3.13 - register.php
Except for having to comment out the include statements, everything else works.
  • 0

#3
Dragon

Dragon

    All Around Computer Nut

  • Topic Starter
  • Retired Staff
  • 2,682 posts
that double <?php was a bad edit on my part from trying to fix it. I was getting those errors, like you see in the screenshots, from the very beginning.

Except for having to comment out the include statements, everything else works.


Which include statement are you referring to, one or both?

Edited by Dragon, 04 December 2005 - 09:55 PM.

  • 0

#4
Dragon

Dragon

    All Around Computer Nut

  • Topic Starter
  • Retired Staff
  • 2,682 posts
update,
I just tried to comment out the include entries, unless I missed one somewhere same problem.

canoeingkid, when you tried that did you use FF or IE?
  • 0

#5
gust0208

gust0208

    Member

  • Member
  • PipPipPip
  • 311 posts
Hello,

I made a few minor changes to the code and got it to load with no problems in IE and Firefox, I will attached the modified php file and also show here in the message what I changed. The changes revolved around the couple of very long echo statements that had word-wrapped and could give errors (this may not be the problem in your original code) and you had a couple of extra {'s and an else statement with no ending. Onto the code!

[quote name='Dragon' date='Dec 4 2005, 06:07 PM' post='470912']
ok, i have torn this code apart over and over again. there must be somthing i'm missing, in the html editor's preview window it comes out perfectly, however when I actually load the file up in Firefox i get a totally different response.

here is the code
<body>
<?php # Script 3.13 - register.php
$page_title = 'Register';
include ('./includes/header.html');
if (isset($_POST['submitted'])) {
$errors = array();
if (empty($_POST['name'])) {
$errors[] = 'You forgot to enter your name.';
}
if (empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email address.';
}
if (!empty($_POST['password1'])) {
if ($_POST['password1'] != $_POST ['password2']) {
$errors[] = 'Your password did not match the confirmed password.';
}
} else {
$errors[] = 'You forgot to enter your password.';
}
if (empty($errors)) {
$body = "Thank you for registering with our site!\nYour password is '{$_POST['password1']}'. \n\nSincerely,\nUs";
mail ($_POST['email'], 'Thank you for registering!', $body, 'From: [email protected]');
echo '<h1 id="mainhead">Thank you!</h1><p>You are now registered. An email has been sent to your email address confirming the information.</p><p><br /></p>';
} else {
echo '<h1 id="mainhead">Error!</h1><p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) {
echo " - $msg<br />\n";
}
echo '</p><p>Please go back and try again.</p><p><br /></p>';
}
}
[/quote]
Here is the extra else statement that has a beginning { but no end } and no code. I am not sure if else statements and {}'s can span separate <?php ?> php code blocks, so I just removed them.
# else {
[quote name='Dragon' date='Dec 4 2005, 06:07 PM' post='470912']
?>
<h2>Register</h2>
<form action="register.php" method="post">
  <p>Name: <input name="name" size="20"
 maxlength="40" type="text"></p>
  <p>Email Address: <input name="email" size="20"
 maxlength="40" type="text"> </p>
  <p>Password: <input name="password1" size="10"
 maxlength="20" type="password"></p>
  <p>Confirm Password: <input name="password2"
 size="10" maxlength="20" type="password"></p>
  <p><input name="submit" value="Register"
 type="submit"></p>
  <input name="submitted" value="TRUE" type="hidden">
</form>
[/quote]
Here I just removed the ending } parenthesis that you had from the else statment above. Do you only want to display the footer html if the form has been submitted?
#<?php }
<?php
[quote name='Dragon' date='Dec 4 2005, 06:07 PM' post='470912']
include ('./includes/footer.html');
?>
and here is a screen shot of what it looks like in my FF browser, Until i get this resolved I can't check the the database connectivity end of it.
[/quote]

Hope that helps a little bit and I attached the slighly modified code.

Cheers,
Tom

Attached Files

  • Attached File  test.php   1.76KB   35 downloads

  • 0

#6
Canoeingkidd

Canoeingkidd

    Malware Expert

  • Retired Staff
  • 148 posts

that double <?php was a bad edit on my part from trying to fix it. I was getting those errors, like you see in the screenshots, from the very beginning.

Which include statement are you referring to, one or both?

Both, I had to comment them out because I don't have the files being included...you should.

The only other problem I had on my development server was with the mail function (presumably because I don't have sendmail configured in php.ini).

Long, word-wrapped echo statements shouldn't cause any errors as PHP is not whitespace sensitive.

I looks like there is a problem with this echo statement, however:
echo '<h1 id="mainhead">Thank you!</h1><p>You are now registered. An email has been sent to your email address confirming the information.</p><p><br /></p>';
From the screenshot it looks like echo stops at the 'm' in "information" and then picks up again at the single quote at the end of the statement?? Very odd. Does gust0208's modification work any better?
  • 0

#7
Dragon

Dragon

    All Around Computer Nut

  • Topic Starter
  • Retired Staff
  • 2,682 posts
Actually yes.
I got my server set up and everything worked out, I needed to comment those include statements out also since I haven't made the header and footer files yet. Working on those now.

thanks for looking gang.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP