Jump to content

parse error?


YoungDuPage

Recommended Posts

The server says: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/kazafoxc/public_html/mailform.php on line 124

<?phpif (isset($_POST['email']))//if "email" is filled out, send email  {  //send email  $email = $_POST['email'];   $subject = $_POST['subject'];  $message = $_POST['message'];  $Parameters = $_POST['name'];  mail("my@example.com", "Subject: $subject",  $message, "From: $email" );  echo "Thank you for using our mail form";  }else//if "email" is not filled out, display the form  {  echo "<form method='post' action='mailform.php'>  Email: <input name='email' type='text' /><br />  Subject: <input name='subject' type='text' /><br />  Message:<br />  <textarea name='message' rows='15' cols='40'>  </textarea><br />  <input type='submit' value="Send" class="button" />  </form>";  }?>

line 124 is right before the last line. i dont know what the problem is?

Link to comment
Share on other sites

Change the double quotes on this line for single quotes, or escape them:<input type='submit' value="Send" class="button" />

Link to comment
Share on other sites

I changed the code you posted, this should work:

<?phpif (isset($_POST['email']))//if "email" is filled out, send email  {  //send email  $email = $_POST['email'];   $subject = $_POST['subject'];  $message = $_POST['message'];  $Parameters = $_POST['name'];  mail("my@example.com", "Subject: $subject",  $message, "From: $email" );  echo "Thank you for using our mail form";  }else//if "email" is not filled out, display the form  {  echo "<form method='post' action='mailform.php'>  Email: <input name='email' type='text' /><br />  Subject: <input name='subject' type='text' /><br />  Message:<br />  <textarea name='message' rows='15' cols='40'>  </textarea><br />  <input type='submit' value='Send' class='button' />  </form>";  }?>

However, you could also rewrite it like this:

<?phpif (isset($_POST['email']) == true &&   isset($_POST['subject']) == true &&   isset($_POST['message']) == true) //if "email" is filled out, send email{  //send email  $email = $_POST['email'];   $subject = $_POST['subject'];  $message = $_POST['message'];  $Parameters = $_POST['name'];  mail("my@example.com", "Subject: $subject", $message, "From: $email" );  echo "Thank you for using our mail form";} else //if "email" is not filled out, display the form{  echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>",  "\r\n  Email: <input name='email' type='text' /><br />",  "\r\n  Subject: <input name='subject' type='text' /><br />",  "\r\n  Message:<br />",  "\r\n  <textarea name='message' rows='15' cols='40'></textarea><br />",  "\r\n  <input type='submit' value='Send' class='button' />",  "\r\n</form>";}?>

You could also instead of just checking if the fields are set, validate them against your own rules.Second, this form will always post its data to itself, renaming this file will not cause the submit to become invalid this way :)Third, this way of echoing makes it a little more readable, and you now have controll over how you write your strings. They can be indented, makes your complete code more organised.

Link to comment
Share on other sites

im not very familiar with php. i just need another parameter to request the users name.

<?phpif (isset($_POST['email']))//if "email" is filled out, send email  {  //send email  $email = $_POST['email'];  $subject = $_POST['subject'];  $message = $_POST['message'];  $Parameters = $_POST['name'];  mail("team@kazafox.com", "Subject: $subject",  $message, "From: $email" );  echo "Thank you for using our mail form";  }else//if "email" is not filled out, display the form  {  echo "<form method='post' action='mailform.php'>  <p><label>Email:</label><br>	<input name='email' type='text' /><br />  <p><label>Name:</label><br>	<input name='name' type='text' /><br />  <p><label>Subject:</label><br>	<input name='subject' type='text' /><br />  <p><label>Message:</label><br>	  <textarea name='message' rows='15' cols='40'>  </textarea><br />  <input type='submit' value='Send' class='button' />  </form>";  }?>

Link to comment
Share on other sites

These lines show the label and the input: <p><label>Email:</label><br> <input name='email' type='text' /><br />You can copy and paste those to put whatever you want in the form, wherever you want it. The corresponding line in the PHP script:$email = $_POST['email'];Uses the same value in the "name" attribute in the input tag to get the value that was submitted. You can put their name in the subject, or the from email address, or the message, or wherever you want it to appear in the email.

Link to comment
Share on other sites

can you make multiple data collecting files? or can you only have one file called mailform.php? and how do i make one of the variables a selection. such as:

								<select name="business">				<option value="">::::Business Cards::::</option>				<option value="">::::Email Marketing::::</option>				<option value="" selected="selected">::::Marketing Networks::::</option>

Link to comment
Share on other sites

can you make multiple data collecting files? or can you only have one file called mailform.php? and how do i make one of the variables a selection. such as:$userschoice

<select name="business"><option value="">::::Business Cards::::</option><option value="">::::Email Marketing::::</option><option value="" selected="selected">::::Marketing Networks::::</option></select>

Link to comment
Share on other sites

can you make multiple data collecting files? or can you only have one file called mailform.php?
You can't submit a form to multiple pages (at least without using an asynchronous method such as AJAX). Your processing page doesn't, however, have to be called mailform.php.
and how do i make one of the variables a selection. such as: $userschoice
<select name="userschoice"><option value="1">::::Business Cards::::</option><option value="2">::::Email Marketing::::</option><option value="3" selected="selected">::::Marketing Networks::::</option></select>

Will end up in $_POST['userschoice'] (the selected option's value will be assigned, so giving them all a value of "" isn't really helpful).

Link to comment
Share on other sites

Yah. The "T" stands for token and is so generic to parsing errors that it means everything and nothing. The key word in there is "string." How do strings go wrong? Usually in the quotation marks. Ingolme and JSG identified the correct error in posts 2-3 above. The reason it's an error is that when your string reached this point:value="the quote was interpreted as a closing quote, and the string is ended. So now the parser is trying to figure out the meaning of the stuff that comes after, and it hits some problems: 1. there is no ";" at the end of the previous statement, and 2. the statement-like structureSend" class="button" /></form>";makes no sense in PHP.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...