Can anyone find the error in this line of code?

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
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Can anyone find the error in this line of code?

Post 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...
imstupid
Forum Commoner
Posts: 84
Joined: Fri Feb 18, 2005 1:24 pm

Post by imstupid »

try escaping the double quotes around contact.php:


<a href=\"contact.php\"> or use singles. I always forget
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post 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.
imstupid
Forum Commoner
Posts: 84
Joined: Fri Feb 18, 2005 1:24 pm

Post 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.
Revan
Forum Commoner
Posts: 83
Joined: Fri Jul 02, 2004 12:37 am
Location: New Mexico, USA
Contact:

Post 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\.
hustler
Forum Newbie
Posts: 6
Joined: Thu Jul 21, 2005 2:26 am

Post by hustler »

is it contact.php or Contact.php?
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

Post 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>';
Post Reply