Form help in php and html

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Form help in php and html

Post by akimm »

Alright I have this form set to reside on a page and send a users info to me I cannot understand where I've gone wrong, I've trouble shot this code for a while and I'm stumped, can anyone help?

Code: Select all

<form action="send_word.php" method="POST">
<p><b>your name</b>
<input type="text" name="name" size="30"></p>

<p><b>your email</b>
<input type="text" name="sender_email" size="30"></p>

<p><b>your word</b>
<input type="text" name="word" size="30"></p>

<p><b>definition</b>
<TEXTAREA NAME="definition" COLS="30" ROWS="5" 

WRAP="virtual"></TEXTAREA></P>

<p><input type="submit" name="submit" value="send your word!"></p>


<?php 
if ($_POST[name] == "" ||
    ($_POST[sender_email] == "" ||
    ($_POST[word] == "" ||
    ($_POST[definition] =="")
 
$msg = 'E-MAIL SENT FROM THE CLAIRICTIONARY\n';
$msg .= "Sender's NAME: \t$_POST[name]\n";
$msg .= "Sender's EMAIL:\t$_POST[sender_email]\n";
$msg .= "Sender's WORD:\t$_POST[WORD]\n";
$msg .= "Sender's definition:\t$_POST[definition]\n";
$to = "dailylifez@yahoo.com";
$subject = "Clairictionary words";
$mailtoheaders = "From: Akimm <Sean@akimm.com>\n";
$mailheaders .= "Reply-To: $_POST[sender_email]\n";

mail($to, $subject, $msg, $mailheaders);
?>
<html>
<head>
</head>
<body>
<h1> the following email has been sent!</h1>

<P><b>Your Name:</b><br>
<? echo "$_POST[name]"; ?>
<P><b>Your E-Mail Address:</b><br>
<? echo "$_POST[sender_email]"; ?>
<P><b>Message:</b><br>
<? echo "$_POST[word]"; ?>
<P><b>definition:</b><br>
<? echo "$_POST[definition]"; ?>
 
</body>
</html>

the html is here

Code: Select all

<form action="send_simpleform.php" method="POST">
<p><b>your name</b>
<input type="text" name="name" size="30"></p>

<p><b>your email</b>
<input type="text" name="sender_email" size="30"></p>

<p><b>your word</b>
<input type="text" name="word" size="30"></p>

<p><b>definition</b>
<TEXTAREA NAME="definition" COLS="30" ROWS="5" 

WRAP="virtual"></TEXTAREA></P>

<p><input type="submit" name="submit" value="send your word!"></p>
Thanks for any help provided!!!
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

any output?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

There's all kinds of things wrong with this. Firstly you should place your array keys in quotes if they are strings:

Code: Select all

$_POST['foo'];

//not
$_POST[foo];
Secondly this:

Code: Select all

if ($_POST[name] == "" ||
    ($_POST[sender_email] == "" ||
    ($_POST[word] == "" ||
    ($_POST[definition] =="")
Is worng... there;s parentheses all over the place and unbalanced there.... maybe?

Code: Select all

if ($_POST[name] == "" ||
    $_POST[sender_email] == "" ||
    $_POST[word] == "" ||
    $_POST[definition] =="")
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Also, your "if" statement will only execute the first line underneath it unless you use curly braces to mark out a whole block of statements:

Code: Select all

<?php
if ($_POST['name'] != "" &&
    $_POST['sender_email'] != "" &&
    $_POST['word'] != "" &&
    $_POST['definition'] !="")
 {
$msg = 'E-MAIL SENT FROM THE CLAIRICTIONARY\n';
$msg .= "Sender's NAME: \t$_POST[name]\n";
$msg .= "Sender's EMAIL:\t$_POST[sender_email]\n";
$msg .= "Sender's WORD:\t$_POST[word]\n";
$msg .= "Sender's definition:\t$_POST[definition]\n";
$to = "dailylifez@yahoo.com";
$subject = "Clairictionary words";
$mailtoheaders = "From: Akimm <Sean@akimm.com>\n";
$mailheaders .= "Reply-To: $_POST[sender_email]\n";

mail($to, $subject, $msg, $mailheaders);
}
?>
And lastly I think you need && not || because you want all of those fields complete in order to submit that info.

EDIT | Also, the array keys and variable names are case sensitive so WORD whould be lowercase.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

thanks

Post by akimm »

I will try these fixes hopefully they are enough.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Error

Post by akimm »

Parse error: parse error, unexpected T_VARIABLE in /nfs/cust/8/25/05/650528/web/clairictionary/send_simpleform.php on line 23

after the fixes you so kindly provided, I'm lost as to what this error even means let alone where the problem is consistent
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Error

Post by Chris Corbyn »

akimm wrote:Parse error: parse error, unexpected T_VARIABLE in /nfs/cust/8/25/05/650528/web/clairictionary/send_simpleform.php on line 23

after the fixes you so kindly provided, I'm lost as to what this error even means let alone where the problem is consistent
Can you post the code the way it looks now please? Including line 23.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

Code: Select all

[php]
<form action="send_word.php" method="POST">
<p><b>your name</b>
<input type="text" name="name" size="30"></p>

<p><b>your email</b>
<input type="text" name="sender_email" size="30"></p>

<p><b>your word</b>
<input type="text" name="word" size="30"></p>

<p><b>definition</b>
<TEXTAREA NAME="definition" COLS="30" ROWS="5" 

WRAP="virtual"></TEXTAREA></P>

<p><input type="submit" name="submit" value="send your word!"></p>

<?php 
if ($_POST['name'] != "" && 
    $_POST['sender_email'] != "" && 
    $_POST['word'] != "" && 
    $_POST['definition'] !="") 
 { 
$msg = 'E-MAIL SENT FROM THE CLAIRICTIONARY\n'; 
$msg .= "Sender's NAME: \t$_POST['name']\n"; 
$msg .= "Sender's EMAIL:\t$_POST['sender_email']\n"; 
$msg .= "Sender's WORD:\t$_POST['word']\n"; 
$msg .= "Sender's definition:\t$_POST['definition']\n"; 
$to = "dailylifez@yahoo.com"; 
$subject = "Clairictionary words"; 
$mailtoheaders = "From: Akimm <Sean@akimm.com>\n"; 
$mailheaders .= "Reply-To: $_POST['sender_email']\n"; 

mail($to, $subject, $msg, $mailheaders); 
} 
?>



<html>
<head>
</head>
<body>
<h1> the following email has been sent!</h1>

<P><b>Your Name:</b><br>
<? echo "$_POST['name']"; ?>
<P><b>Your E-Mail Address:</b><br>
<? echo "$_POST['sender_email']"; ?>
<P><b>Message:</b><br>
<? echo "$_POST['word']"; ?>
<P><b>definition:</b><br>
<? echo "$_POST['definition']"; ?>
 
</body>
</html>
[/php]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Anywhere you see something like this...

Code: Select all

<?php
$msg .= "Sender's NAME: \t$_POST['name']\n";
?>
Change it to something like...

Code: Select all

<?php
$msg .= "Sender's NAME: \t" . $_POST['name'] . "\n";

// OR this...

$msg .= "Sender's NAME: \t{$_POST['name']}\n";
?>
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Alrighty

Post by akimm »

Thanks again, I will try this and see if that does the trick.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

another error message

Post by akimm »

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /nfs/cust/8/25/05/650528/web/clairictionary/send_simpleform.php on line 32

Code: Select all

<form action="send_word.php" method="POST">
<p><b>your name</b>
<input type="text" name="name" size="30"></p>

<p><b>your email</b>
<input type="text" name="sender_email" size="30"></p>

<p><b>your word</b>
<input type="text" name="word" size="30"></p>

<p><b>definition</b>
<TEXTAREA NAME="definition" COLS="30" ROWS="5"

WRAP="virtual"></TEXTAREA></P>

<p><input type="submit" name="submit" value="send your word!"></p>

<?php
if ($_POST['name'] != "" &&
    $_POST['sender_email'] != "" &&
    $_POST['word'] != "" &&
    $_POST['definition'] !="")
 {
$msg = 'E-MAIL SENT FROM THE CLAIRICTIONARY\n';
$msg .= "Sender's NAME: \t{$_POST['name']}\n";
$msg .= "Sender's EMAIL:\t{$_POST['sender_email']}\n";
$msg .= "Sender's WORD:\t{$_POST['word']}\n";
$msg .= "Sender's definition:\t{$_POST['definition']}\n";
$to = "dailylifez@yahoo.com\n";
$subject = "Clairictionary words\n";
$mailtoheaders = "From: Akimm <Sean@akimm.com>\n";
$mailheaders .= "Reply-To: $_POST['sender_email']\n";

mail($to, $subject, $msg, $mailheaders);
}
?>



<html>
<head>
</head>
<body>
<h1> the following email has been sent!</h1>

<P><b>Your Name:</b><br>
<? echo "$_POST['name']"; ?>
<P><b>Your E-Mail Address:</b><br>
<? echo "$_POST['sender_email']"; ?>
<P><b>Message:</b><br>
<? echo "$_POST['word']"; ?>
<P><b>definition:</b><br>
<? echo "$_POST['definition']"; ?>

</body>
</html>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Sorry, should have been more specific. I meant anywhere a global/array var was used within double quotes either concatenate the variable or wrap it in curly braces({}). Try this and see if it works...

Code: Select all

<form action="send_word.php" method="POST">
<p><b>your name</b>
<input type="text" name="name" size="30"></p>

<p><b>your email</b>
<input type="text" name="sender_email" size="30"></p>

<p><b>your word</b>
<input type="text" name="word" size="30"></p>

<p><b>definition</b>
<TEXTAREA NAME="definition" COLS="30" ROWS="5"

WRAP="virtual"></TEXTAREA></P>

<p><input type="submit" name="submit" value="send your word!"></p>

<?php
if ($_POST['name'] != "" &&
    $_POST['sender_email'] != "" &&
    $_POST['word'] != "" &&
    $_POST['definition'] !="")
{
$msg = "E-MAIL SENT FROM THE CLAIRICTIONARY\n";
$msg .= "Sender's NAME: \t{$_POST['name']}\n";
$msg .= "Sender's EMAIL:\t{$_POST['sender_email']}\n";
$msg .= "Sender's WORD:\t{$_POST['word']}\n";
$msg .= "Sender's definition:\t{$_POST['definition']}\n";
$to = "dailylifez@yahoo.com\n";
$subject = "Clairictionary words\n";
$mailtoheaders = "From: Akimm <Sean@akimm.com>\n";
$mailheaders .= "Reply-To: {$_POST['sender_email']}\n";

mail($to, $subject, $msg, $mailheaders);
}
?>



<html>
<head>
</head>
<body>
<h1> the following email has been sent!</h1>

<P><b>Your Name:</b><br>
<?php echo $_POST['name']; ?>
<P><b>Your E-Mail Address:</b><br>
<?php echo $_POST['sender_email']; ?>
<P><b>Message:</b><br>
<?php echo $_POST['word']; ?>
<P><b>definition:</b><br>
<?php echo $_POST['definition']; ?>

</body>
</html>
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

ah thanks

Post by akimm »

thanks thanks.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Did it work?
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Yes

Post by akimm »

This has been an ungoing experiment with coding. These two programs you guys helped with are of my first few I have.
Post Reply