/    Sign up×
Community /Pin to ProfileBookmark

Simple post but can only retrieve first word

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:

[CODE]<input name=”ShowEmail” type=”hidden” value= <? echo $ShowEmail; ?>>
<input name=”CompanyNameE” type=”hidden” value= <? echo $CompanyNameE; ?>>[/CODE]

When I retrieve this on the “action” page with:

[CODE]$ShowEmail=$_POST[‘ShowEmail’];
$CompanyNameE=$_POST[‘CompanyNameE’];
[/CODE]

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?

to post a comment
PHP

15 Comments(s)

Copy linkTweet thisAlerts:
@designer4lifeFeb 25.2007 — try print_r($_POST) to get an array of your post data.
Copy linkTweet thisAlerts:
@SkywoolfauthorFeb 25.2007 — 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] => [email protected]

[message] => test

[ShowEmail] => [email protected]

[CompanyNameE] => Frank

[Submit] => Send Email )

CompanyNameE should be Frank Woolf Motors. Otherwise all is correct
Copy linkTweet thisAlerts:
@SheldonFeb 25.2007 — maybe post the whole form and the php that processes it

then we can help more
Copy linkTweet thisAlerts:
@SkywoolfauthorFeb 25.2007 — 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 .
[CODE]<?
$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> [/CODE]




This page receives the data from the above page and sends the email. Everything works fine except the $CompanyNameE only contains the first word:
[CODE]<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>[/CODE]
Copy linkTweet thisAlerts:
@SheldonFeb 25.2007 — 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]

[code=php]<?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. "."rn".
.$CompanyNameE."rn".
"Best regards from the Car Sales Team."."rn".
"http://www.carsalesasia.com"."rn";

mail($ShowEmail,"Enqiry from Car Sales Asia User",$message,"From: The Car Sales Asia Dealer Finder Service");
}else{
echo("Submit the form");
}
?>[/code]
Copy linkTweet thisAlerts:
@SkywoolfauthorFeb 25.2007 — 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.
Copy linkTweet thisAlerts:
@SkywoolfauthorFeb 25.2007 — 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
Copy linkTweet thisAlerts:
@SkywoolfauthorFeb 25.2007 — Fixed it!

I added a line

$message."rn".


after $CompanyNameE."rn".

Many thanks for the help.

Now I can make it look pretty and put in some error checking
Copy linkTweet thisAlerts:
@SkywoolfauthorFeb 25.2007 — Oops! Not quite. It is all working except the name is still one word!
Copy linkTweet thisAlerts:
@NightShift58Feb 25.2007 — Change:[code=php]<input name="ShowEmail" type="hidden" value= <? echo $ShowEmail; ?>>
<input name="CompanyNameE" type="hidden" value= <? echo $CompanyNameE; ?>>[/code]
to:[code=php]<input name="ShowEmail" type="hidden" value='<? echo $ShowEmail; ?>'>
<input name="CompanyNameE" type="hidden" value='<? echo $CompanyNameE; ?>'>[/code]
If you don't quote your values...
Copy linkTweet thisAlerts:
@SkywoolfauthorFeb 25.2007 — 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.
Copy linkTweet thisAlerts:
@NightShift58Feb 25.2007 — Just remember that fixing the output doesn't help if the input is wrong... Always check there first...
Copy linkTweet thisAlerts:
@SkywoolfauthorFeb 25.2007 — Absolutely. I spent hours checking both pages getting nowhere ?
Copy linkTweet thisAlerts:
@SheldonFeb 25.2007 — Just remember that fixing the output doesn't help if the input is wrong... Always check there first...[/QUOTE]

Absolutely. I spent hours checking both pages getting nowhere [/quote]

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.
Copy linkTweet thisAlerts:
@SkywoolfauthorFeb 26.2007 — 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.
×

Success!

Help @Skywoolf spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...