Page 1 of 1
Can anyone find the error in this line of code?
Posted: Fri Jul 22, 2005 12:59 pm
by bruceg
Hello,
this line of code produces an error, and I am not sure how to fix.
Code: Select all
{echo "$key has not been completed. Please <a href="Contact.php">Try again!</a>";die;}
the error given is:
Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /hsphere/local/home/bruceg/inspired-evolution.com/simplescript.php on line 12
heobviosly I need to add single quotes, but I am not exactly sure where...
Posted: Fri Jul 22, 2005 1:04 pm
by imstupid
try escaping the double quotes around contact.php:
<a href=\"contact.php\"> or use singles. I always forget
Posted: Fri Jul 22, 2005 1:38 pm
by bruceg
well using <a href=\'contact.php\'> works but the link doesn't work, even though that is the correct file name. Ideally what I am wanting is something that will hi-light the required fields that haven't been completed. Currently with this script all fields are required.
Here is the complete current script
Code: Select all
<?php
$subject = 'There has been a disturbance in the force!'; // Subject of email sent to you.
$emailadd = 'webguync@gmail.com'; // Your email address. This is where the form information will be sent.
$url = 'Thankyou.php'; // Where to redirect after form is processed.
$req = '1'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key has not been completed. Please <a href=\'Contact.php\'>Try again!</a>";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>
the form is at
http://www.inspired-evolution.com/Contact.php
P.S I found this form at phpfreaks, I didn't write it myself, but I would like to modify it to fot my needs ot find a better one on-line.
Posted: Fri Jul 22, 2005 2:36 pm
by imstupid
Hey
I'm sure you've probably checked, but are you sure contact.php is in the right directory?
You could also try:
Code: Select all
if ($name == "") {
echo "$key has not been completed. Please try again.<br><br>";
echo "<a href='javascript:history.back(1);'>Back</a>";
}
Second, I'm not sure you need the two semi-colons after your die... I always use this format:
Code: Select all
$example = mysql_query("SELECT something FROM tablename WHERE column='whatever'")
or die(mysql_error());
when working with the die's becasue it shoots out some kind of error. Try that format instead to see if it helps, but since I don't know what the h-e-double-hockeysticks I'm doing, one of the gurus could probably suggest something better.
Posted: Fri Jul 22, 2005 2:55 pm
by Revan
Code: Select all
<?php
$subject = 'There has been a disturbance in the force!'; // Subject of email sent to you.
$emailadd = 'webguync@gmail.com'; // Your email address. This is where the form information will be sent.
$url = 'Thankyou.php'; // Where to redirect after form is processed.
$req = '1'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{
echo "$key has not been completed. Please <a href='Contact.php'>Try again!</a>";
die;
}
}
$j = strlen($key);
if ($j >= 20)
{
echo "Name of form element $key cannot be longer than 20 characters";
die;
}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{
$space .= ' ';
}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>
You're putting slashes where they are not needed, and thus turning the URL literally, into \contact.php\.
Posted: Fri Jul 22, 2005 4:49 pm
by hustler
is it contact.php or Contact.php?
Posted: Fri Jul 22, 2005 4:57 pm
by TheOracle
First prize should go to Revan.
You most definately do not need the slashes. You could even change it to:
Code: Select all
echo '$key has not been completed. Please <a href="Contact.php">Try again!</a>';
Also, is the $key at the beginning not a variable? In which case it should read:
Code: Select all
echo $key.' has not been completed. Please <a href="Contact.php">Try again!</a>';