Click to See Complete Forum and Search --> : Simple post but can only retrieve first word


Skywoolf
02-25-2007, 01:48 AM
I realize I may be doing something dumb (I am a PHP beginner).

I have a very simple form to enter data to send an email. A fragment of the form is:
<input name="ShowEmail" type="hidden" value= <? echo $ShowEmail; ?>>
<input name="CompanyNameE" type="hidden" value= <? echo $CompanyNameE; ?>>

When I retrieve this on the "action" page with:
$ShowEmail=$_POST['ShowEmail'];
$CompanyNameE=$_POST['CompanyNameE'];


I only get the first word of the string $CompanyNameE.

Other fields in the same form with more than one word are OK

I have tried changing the syntax every way I can think of but always get the same result.

Can anyone with tell me what dumb mistake I am making?

designer4life
02-25-2007, 02:17 AM
try print_r($_POST) to get an array of your post data.

Skywoolf
02-25-2007, 02:26 AM
Thanks that could be also very useful in future scripts.

I tried it and got this (reformatted to make it easy to read):

Array (
[subject] => Enquiry from a Car Sales Asia user
[from] => Fred
[emailaddress] => fred@bloggs.com
[message] => test
[ShowEmail] => frank@frankwoolf.com
[CompanyNameE] => Frank
[Submit] => Send Email )

CompanyNameE should be Frank Woolf Motors. Otherwise all is correct

Sheldon
02-25-2007, 02:51 AM
maybe post the whole form and the php that processes it
then we can help more

Skywoolf
02-25-2007, 03:10 AM
Thanks.
This page receives two variables from a form. I have checked with temporary echo statements at the end of the page and all data looks like it is correct .
<?
$CompanyNameE=$_POST['CompanyNameE'];
$ShowEmail=$_POST['ShowEmail'];

?>
<form name="email" action="sent_mail.php" method="post">
<table width="600" border="0" cellspacing="0" cellpadding="4">
<tr>
<td height="30" colspan="2" bgcolor="#0000FF"><font color="#FFFFFF" size="3" face="Arial, Helvetica, sans-serif">Send Email to <? echo $CompanyNameE ?></font></td>
</tr>
<tr>
<td width="149"><font size="2" face="Arial, Helvetica, sans-serif">Subject</font></td>
<td width="435"><input name="subject" type="text" value="Enquiry from a Car Sales Asia user" size="50" maxlength="60"></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">Your Name </font></td>
<td><input name="from" type="text" size="50" maxlength="60"></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">Your email Address</font></td>
<td><input name="emailaddress" type="text" size="50" maxlength="60"></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">Message</font></td>
<td><textarea name="message" cols="50" rows="10"></textarea><br><br>
</td>
</tr>
<tr>
<td><input name="ShowEmail" type="hidden" value= <? echo $ShowEmail; ?>>
<input name="CompanyNameE" type="hidden" value= <? echo $CompanyNameE; ?>></td>
<td><center><input name="Submit" type="submit" value="Send Email"></center></td
></tr>
</table>
</form>



This page receives the data from the above page and sends the email. Everything works fine except the $CompanyNameE only contains the first word:
<body>
<table width="600" border="0" cellspacing="0" cellpadding="4">
<tr>
<td>
<?
$subject=$_POST['subject'];
$from=$_POST['from'];
$emailaddress=$_POST['emailaddress'];
$message=$_POST['message'];
$ShowEmail=$_POST['ShowEmail'];
$CompanyNameE=$_POST['CompanyNameE'];

$message="Message to ".$CompanyNameE."

".$from." has sent the following message from the Car Sales Asia Dealer Finder Service.

".$message."


Best regards from the Car Sales Team.
http://www.carsalesasia.com
";

$message = stripslashes($message);
mail($ShowEmail,"Enqiry from Car Sales Asia User",$message,"From: The Car Sales Asia Dealer Finder Service");
?>
</tr>
</table>

</body>

Sheldon
02-25-2007, 03:25 AM
is that it? and you dont get errors from it? juese fuŠk me drunk thats a mess.

try this, [excluding the table sh!t]

<?php

if(isset($_POST['submit'])){
$subject = $_POST['subject'];
$from = $_POST['from'];
$emailaddress = $_POST['emailaddress'];
$message =$_POST['message'];
$ShowEmail =$_POST['ShowEmail'];
$CompanyNameE ="Message to " . $_POST['CompanyNameE'];

$messge = $from." has sent the following message from the Car Sales Asia Dealer Finder Service. "."\r\n".
.$CompanyNameE."\r\n".
"Best regards from the Car Sales Team."."\r\n".
"http://www.carsalesasia.com"."\r\n";

mail($ShowEmail,"Enqiry from Car Sales Asia User",$message,"From: The Car Sales Asia Dealer Finder Service");
}else{
echo("Submit the form");
}
?>

Skywoolf
02-25-2007, 03:43 AM
Heh heh, well I did say I was a beginner :)

Actually it started off a lot simpler but the mess got worse as I tried everything to get it to work, even copying and changing old scripts that use tables.

I tried your script and got an "Unexpected . in line 25 error" so I removed the . at the beginning.

I then corrected a typo by putting the a in $message.

I now get the message "Submit the form" so I guess maybe there is a problem with the first line.

Skywoolf
02-25-2007, 03:52 AM
Just noticed I have Submit with an upper case S in the entry form so I changed it in the first line on your code.

It now sends the email but the name is still one word and there is no message.

This is the received email

Fred has sent the following message from the Car Sales Asia Dealer Finder Service.
Message to Frank
Best regards from the Car Sales Asia Team.
http://www.carsalesasia.com

Skywoolf
02-25-2007, 03:59 AM
Fixed it!

I added a line

$message."\r\n".


after $CompanyNameE."\r\n".

Many thanks for the help.

Now I can make it look pretty and put in some error checking

Skywoolf
02-25-2007, 04:01 AM
Oops! Not quite. It is all working except the name is still one word!

NightShift58
02-25-2007, 06:14 AM
Change:<input name="ShowEmail" type="hidden" value= <? echo $ShowEmail; ?>>
<input name="CompanyNameE" type="hidden" value= <? echo $CompanyNameE; ?>>to:<input name="ShowEmail" type="hidden" value='<? echo $ShowEmail; ?>'>
<input name="CompanyNameE" type="hidden" value='<? echo $CompanyNameE; ?>'>If you don't quote your values...

Skywoolf
02-25-2007, 06:23 AM
Wow, many thanks NightShift58.

That was the solution.

Its been driving me crazy and I thought all along it would be something simple but I got a bonus with the much better code from Sheldon.

Thanks to you both.

NightShift58
02-25-2007, 06:31 AM
Just remember that fixing the output doesn't help if the input is wrong... Always check there first...

Skywoolf
02-25-2007, 06:37 AM
Absolutely. I spent hours checking both pages getting nowhere :)

Sheldon
02-25-2007, 03:34 PM
Just remember that fixing the output doesn't help if the input is wrong... Always check there first...

Absolutely. I spent hours checking both pages getting nowhere

missed the point, NightShift is saying you need to validate the post data, making sure nothing required is missing or no data posted can hack your script/server.

Skywoolf
02-25-2007, 06:14 PM
Yep, I think my mistake was that I checked the contents of the variable many times on the post page and it was fine so I assumed it was posted OK and received wrong. What I see know is that even though the contents of the variable were OK on the post page they were not posted OK.

I wish I knew as much as you guys. I would be really stuck sometimes without help from experts.

Thanks again.