Forum Moderators: coopster
I am having trouble with a php self in the following code, using it either like this
print "<form action='<?=echo $_SERVER['PHP_SELF']?>' method='post'>
or this without the echo like this.
print "<form action='<?=$_SERVER['PHP_SELF']?>' method='post'>
This is the error message I am getting. Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING for the 'PHP_SELF' line.
Heres everything after the query, everything works fine up to this point.
$result=mysqlquery etc.
while ($row = mysql_fetch_array($result))
{
print "<form action='<?=echo $_SERVER['PHP_SELF']?>' method='post'>
<input type='text' name='anemailadress' size=15>
<input type='submit' name='submit' value='Submitting' /></form>"; //adding the new fields the form will send to here which variables will be sending information to someone email.
$mailto = 'anemailaddress' ;//Email address where the form fields will be sent.
mail($mailto, etc. and so on.;}}";
echo 'this line will work when the php self works, right now I get the error message instead';
?>
Can anyone see what I am doing wrong with the php self and if the new commands that the form is sending to at the end of the form are in the right place? Between the correct brackets and double quotes? Thank you very much.
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
;)
Looks like that helped a little. Now I'm getting the same error but for this line. My first email variable that the form is supposed to send to.
$mailto = 'anemailaddress'
Is it trying to tell me, I supposed to be putting my $_POST['anemailaddress'] directly inot the form itself instead of like how I have it like this?
$mailto = 'anemailaddress'
If so, how, like this?
<input style='type='text' name='$_POST['anemailaddress']' size=15>
Or does the error mean something else.
<input style='type='text' name='$_POST['anemailaddress']' size=15>
Without seeing the context, I can't tell, but you are using single quotes for everything, and you are not using the PHP string concatenation character (.), which does not bode well for syntax checking.
[edited by: cmarshall at 9:18 pm (utc) on Jan. 2, 2007]
Now I'm getting the same error but for this line
You must remember to add the semi-colon to the end ;)
$mailto = 'anemailaddress';
Now for the rest of your question I need some clarification. What are you trying to do? I can see that you are querying a database to extract something (email addresses maybe?) to place into a form, and then you want the contents of that form to be emailed to a specific email address?
Is this even remotely correct? :)
Thanks for the print and echo tip, I thought form fields could only go in prints and echos were well....echos!
$mailto = 'anemailaddress'; Do I need these?
It said it couldn't parse it. I don't have everything in double quotes because its inside a print or echo thats already in double quotes. What about this great string that eelix gave me. Even though I am not getting an error message on the PHP SELF anymore
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>
I'm a bit worried that the double quotes iside the first double quotes is incorrect. I tried changing them to single quotes or removing one of the quotes but it didn't like it again so better leave it as is. Why does this part allow double quotes when the rest doesn't?
Any other good suggestions on what you see wrong with it please get back to me.
<input style='type='text' name='$_POST['anemailaddress']' size=15>
echo "<form action='" . $_SERVER['PHP_SELF'] . "' method='post'>\n";
There's an old saying, attributed to Nasrudin (and repeated by such people as Rita Mae Brown and Will Rogers) that goes:
"Good judgment comes from experience. Experience comes from bad judgment."
I have a great deal of experience. I look forward to good judgment.
I tried putting just a variable in the input fields before, but the mistake I made was not putting these
$email = $_POST['anemailaddress'];
*BEFORE* the form input fields. Makes perfect sense now, good thinking! I hope someone knows the last piece to this so it is finally done.
This is the error I am getting now.
Parse error: parse error, unexpected $ in the ending line?>
Pretty funny just my luck, the last line is the end of the php so something else is obviously wrong. But these php error messages have been clues so I think its just saying it is expecting something more that I don't have just before this?> I just don't know what it is. Or its saying my php opening and closing tags are incorrect within the php somewhere or something else I'm not understanding.
I kept this
echo "<form action='" . $_SERVER['PHP_SELF'] . "' method='post'> but I put this at the end of all the php like I show in my below example. "; Because I am pretty sure it has to wrap around the whole PHP SELF echo. I need to keep it because the form has to send to an email, input fields all by themselves won't work.
This is where I'm at now, I am including all the php opening and closing tags elsewhere in the script so that maybe someone can see something wrong with them that I can't spot, since its saying that
it doesn't like the ending closing tag.
<?php
$con = mysql_connect("my","database","password")
OR die('Could not connect: ' . mysql_error());
mysql_select_db("database", $con) OR die(mysql_error());
if(!$_POST){?><form action="" method="post"><input type="text" size="12" name="websitename"
value="<?=$_POST['websitename']?>" />" /><input type="submit" value="submitting" /></form><?}
else{$modify = mysql_real_escape_string($_POST['websitename']);
$query = "SELECT websitename FROM tablename WHERE websitename = '$modify'";
$result = mysql_query($query) or die('Error with query' . mysql_error());
while ($row = mysql_fetch_array($result))
{
// and on to the sending form fields to an email address.
$mailto = $_POST['anemailaddress'];
$test = $_POST['$row'];
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>
<input type='text' name='$mailto' size=15>
<input type='text' name='$test' size=15>
<input type='submit' name='submit' value='Submitting' /></form>";
$subject = 'Email subject';
$uself = 0;
$headersep = (!isset( $uself ) ¦¦ ($uself == 0))? '\r\n' : '\n' ;
'The E-mail: $mailto\n' . 'Testing field: $test\n';
mail($mailto, $subject, $messageproper, 'From: \'$mailto\' <$mailto>' . $headersep . 'Reply-To: \'$mailto\' <$mailto>' . $headersep);}}";
echo "this line will work when the php self works, right now I get the last error message instead";
?>
The error message says. Parse error: parse error, unexpected $ in the ending line?>
Thanks a lot!
I stripped it down completely. I finally got the items to appear without the error messages but then it wouldn't send to an email so I am analyzing this instead, took everything out but the very basics where the problem is. When I open this in a browser it does not like the line with the POST in it whether I put it on the top or the bottom.
$another = $_POST['anotherfield'];
The error message says. Parse error: unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
Does anyone know why the line with the $_Post won't parse correctly? Once I get this understood, then I can add other items later. Thanks.
<?php
echo "
$mailto = 'websitename@whatever.com';
$another = $_POST['anotherfield'];
<form action='".$_SERVER['PHP_SELF']."' method='post'>
<input type='text' name='$mailto' size=15>
<input type='text' name='$another' size=15>
<input type='submit' name='submit' value='Submitting' /></form>;
$subject = 'Email subject';
$uself = 0;
$headersep = (!isset( $uself ) ¦¦ ($uself == 0))? '\r\n' : '\n' ;
$messageproper = 'The E-mail: $mailto\n' . 'Another field: $another\n';
mail($mailto, $subject, $messageproper, 'From: '$mailto\' <$mailto>' . $headersep . 'Reply-To: \'$mailto\' <$mailto>' . $headersep);";
?>
$another = $_POST['anotherfield'];
<form action='".$_SERVER['PHP_SELF']."' method='post'>
<input type='text' name='$mailto' size=15>
<input type='text' name='$another' size=15>
<input type='submit' name='submit' value='Submitting' /></form>;
You have a number of basic, serious issues here. You really do need to bone up on some of the basics. I'm not saying that to be snooty (I've been there myself). It's just that you are attempting to drive on the highway before finishing diver's ed. You will be frustrated and bedeviled until you figure this out.
In the one section above, you make some terrible assumptions that will cause a whole number of problems. PHP is a scripting language. It does not automatically place anything on the page when you are inside the PHP section (designated by <?php and?>). You treat it like a standard HTML page inside the PHP section, which makes pretty much the entire section a huge syntax error.
Also, when you concatenate strings, you can't just put one next to the other. They must be joined by a period (.).
One way to do the above is like so:
<?php $another = $_POST['anotherfield'];?>
<form action='"<?php echo $_SERVER['PHP_SELF']?>"' method='post'>
<input type='text' name='<?php echo $mailto?>' size=15>
<input type='text' name='<?php echo $another?>' size=15>
<input type='submit' name='submit' value='<?php echo Submitting?>' /></form>;[ Another way is to do it all in echoes, like so:
<?php $another = $_POST['anotherfield'];
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>
<input type='text' name='$mailto' size=15>
<input type='text' name='$another' size=15>
<input type='submit' name='submit' value='Submitting' /></form>";?> I hope this helps.
So I guess I should re evaluate all this again before more testing. Hoping you guys can tell me if this php self is really going to help me.
For instance. PHP SELF looks like when the form sends it is supposed to stay on the same page in order to see the echos on the same page.
But I don't understand how php self is supposed to help send the form fields to the email. I looked all over for this explanation all over the web with no luck. Please explain so I can understand this better. Then I will know how to test further. Thanks all for your nice help, very, very, much.
Thank you for all you nice guys help! If I can't get this to work for what I need, I'll be back in a new post, but it looks promising.
<?php
if($_POST['text']=="")
{
echo "<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">";
echo "<p><input type=\"text\" name=\"text\"><p><input type=\"submit\" value=\"submit\"></p></form>";
}
else
{
echo $_POST['text'];
echo "<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">";
echo "<p><input type=\"text\" name=\"text\"><p><input type=\"submit\" value=\"submit\"></p></form>";
}
?>