Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

76 users online



php problem

php problem

Currently viewing this thread: 1 (0 members and 1 guests)


melee

melee

Neverside Newbie
Status: Offline!

php problem

Hey there, im running this code and getting this error.

Parse error: parse error, unexpected $end in C:\Program Files\Apache Group\Apache2\htdocs\handle_form.php on line 62

im running off localhost and ive set register_globals to on, someone please help if you can. thanks

handle_form.php

PHP:


<html>
<head>
<title>Simple Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php

    
// check name and strip slashes

    
if (strlen($name) > 0) {
        
$name stripslashes($name);
    } else {
        
$name NULL;
    echo 
"You forgot to enter your name!</br><p>";
    }

    
// Check Comments and strip slashes

    
if (strlen($comments) > 0) {
        
$comments stripslashes($comments);
    } else { 
// if there are no comments
        
$comments NULL;
    echo 
"You forgot to add some comments!</br><p>";

    
// Check Email and strip slashes

    
if (!(strlen($email) > 0)) {
        
$email stripslashes($email);
    } else { 
// didnt add email address
        
$email NULL;
    echo 
"You Forgot to add your email!</br><p>";

    
// Check Gender...

    
if (isset($gender)) {

        if (
$gender == 'M') {
        
$message '<b><p>Good day, Sir!</b><p>';
    } elseif (
$gender == 'F') {
        
$message '<b><p>Good day, Madam!</b></p>';
    }

    } else { 
// if no gender was selected...
    
$gender NULL;
    echo 
"You forgot to select your Gender!</br></p>";
    }

    
// If everything was filled out, print the message.

    
if ($name && $comments && $email && $gender){

    echo 
"thankyou <b>$name</b> for the following comment(s):
    <br /><tt>$comments</tt><p>
    We Will reply back to you at <i>$email</i> soon.</p>"
;
    echo 
$message;
    }
?>
</body>
</html> (<--- this is line 62)

form.html

Code:


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<form action="handle_form.php" method="post">

<fieldset><Legend>Enter your information in the form below:</Legend>

<p><b>Name:</b> <input type="text" name="name" size="20" maxlength="40" /></p>

<p><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="60" /></p>

<p><b>Gender:</b> <input type="radio" name="gender" Value="M" /> Male
<input type="radio" name="gender" Value="F" /> Female</p>

<p><b>Age:</b> <select name="age">
<option value="0-30">Under 30</option>
<option value="30-60">Between 30 and 60</option>
<option value="60+">Over 60</option>
</select></p>

<p><b>Comment:</b> <textarea name="comments" rows="3" cols="50"></textarea></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Submit Information" /></div>
</form>

</body>
</html>

ed-d

ed-d

Status: Offline!
PHP:

<?php

// check name and strip slashes
if (strlen($name) > 0
{
    
$name stripslashes($name);

else 
{
    
$name NULL;
    echo 
"You forgot to enter your name!</br><p>";
}
    
// Check Comments and strip slashes
if (strlen($comments) > 0
{
    
$comments stripslashes($comments);

else 

    
// if there are no comments
    
$comments NULL;
    echo 
"You forgot to add some comments!</br><p>";
}

// Check Email and strip slashes
if (strlen($email) > 0)
{
    
$email stripslashes($email);

else 

    
// didnt add email address
    
$email NULL;
    echo 
"You Forgot to add your email!</br><p>";
}

// Check Gender...
if (isset($gender)) 
{
    if (
$gender == 'M'
    {
        
$message '<b><p>Good day, Sir!</b><p>';
    } 
    elseif (
$gender == 'F'
    {
        
$message '<b><p>Good day, Madam!</b></p>';
    }
    else 
    {
        
// if no gender was selected...
        
$gender NULL;
        echo 
"You forgot to select your Gender!</br></p>";
    }
}
    
// If everything was filled out, print the message.
if ($name && $comments && $email && $gender)
{
    echo 
"thankyou <b>$name</b> for the following comment(s):

    <br /><tt>$comments</tt><p>
    We Will reply back to you at <i>$email</i> soon.</p>"
;
    echo 
$message;
}
?>


i think it was that you forgot some closing brackets "}". if u tab them this way u can follow the flow of them easier

melee

melee

Neverside Newbie
Status: Offline!

thanks a heap, i checked through it all and must of missed it.

Sorry bout this but i face another problem that i can't seem to shake.

Notice: Undefined variable: name in C:\Program Files\Apache Group\Apache2\htdocs\handle_form.php on line 11
You forgot to enter your name!

Notice: Undefined variable: comments in C:\Program Files\Apache Group\Apache2\htdocs\handle_form.php on line 22
You forgot to add some comments!

Notice: Undefined variable: email in C:\Program Files\Apache Group\Apache2\htdocs\handle_form.php on line 34
You Forgot to add your email!

If you can help that would be great. Thankyou

ex60

ex60

Wanna-b PS Expert
Status: Offline!

When you use the post method it places all your variables into this syntax $_POST['name']

so just replace all of the instinces of $name, $comments, and $email with $_POST['name'], $_POST['comments'], and $_POST['email']

or you could just re-define th variables before like this

PHP:


<?
$name 
$_POST['name'];
$comments $_POST['comments'];
$email $_POST['email'];
?>

Fitzo

Fitzo

PHP g00n
Status: Offline!

This should do it Smile

PHP:


<?php

// Grab form info
$name $_POST['name'];
$email $_POST['email'];
$comments $_POST['comments'];
$gender $_POST['gender'];

// check name and strip slashes
if (strlen($name) > 0
{
    
$name stripslashes($name);

else 
{
    
$name NULL;
    echo 
"You forgot to enter your name!</br><p>";
}
    
// Check Comments and strip slashes
if (strlen($comments) > 0
{
    
$comments stripslashes($comments);

else 

    
// if there are no comments
    
$comments NULL;
    echo 
"You forgot to add some comments!</br><p>";
}

// Check Email and strip slashes
if (strlen($email) > 0)
{
    
$email stripslashes($email);

else 

    
// didnt add email address
    
$email NULL;
    echo 
"You Forgot to add your email!</br><p>";
}

// Check Gender...
if (isset($gender)) 
{
    if (
$gender == 'M'
    {
        
$message '<b><p>Good day, Sir!</b><p>';
    } 
    elseif (
$gender == 'F'
    {
        
$message '<b><p>Good day, Madam!</b></p>';
    }
    else 
    {
        
// if no gender was selected...
        
$gender NULL;
        echo 
"You forgot to select your Gender!</br></p>";
    }
}
    
// If everything was filled out, print the message.
if ($name && $comments && $email && $gender)
{
    echo 
"thankyou <b>$name</b> for the following comment(s):

    <br /><tt>$comments</tt><p>
    We Will reply back to you at <i>$email</i> soon.</p>"
;
    echo 
$message;
}
?>

___________________

http://www.edenstar.net/images/siggy.gif

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0125 seconds.