【问题标题】:Footer missing on form submission提交表单时缺少页脚
【发布时间】:2017-03-06 11:37:29
【问题描述】:

表单页面本身一切正常,但提交表单后,回显中缺少页脚。我正在收到电子邮件并且标题在那里,问题只是页脚。这是整个页面的代码。有两种单独的表格,一种用于加入,一种用于编辑信息。提交表单后也不显示页脚。 错误日志说

PHP 解析错误:语法错误,意外的 'echo' (T_ECHO),期待 ',' 或 ';'

<?
include("config.php");
include("header.php"); 

if (!$_REQUEST['action']) { ?>

<h1>Join Form</h1>
<div align="justify">
<p>Fill out the form below to join this fanlisting. Please make sure     you've read the rules and if you have a website, that you put a link back up     to <?=$siteurl?> before joining!</p>
<p>Please note: <strong>this form is for joining only</strong>! If you wish to update your member information, please <a href="join.php?action=update">click here</a>.</p>

<script>
function submitonce(theform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}
}
</script>

<div align="center"><form method="post" action="join.php"         onSubmit="submitonce(this)">
<input type="hidden" name="apr" value="-">
<input type="hidden" name="action" value="join">

<table border="0" cellspacing="0" cellpadding="2" width="90%">
<tr></tr><td width="30%">Name:</td>
<td><input type="text" name="name" size="40" class="form"></td>

</tr><tr><td>Email Address:<br>
<strong>Please Note</strong>: <em>All email addresses displayed on the member pages are proctected from SPAM by Javascript.</em></td>
<td><input type="text" name="email" size="40" class="form"><br>
<input type="radio" name="hideemail" value="n" checked> Display My Email Address<br>
<input type="radio" name="hideemail" value="h"> Hide My Email Address</td>

</tr><tr><td>Website:</td>
<td><input type="text" name="url" value="" size="40" class="form"></td>

</tr><tr><td>Country:</td>
<td>
   <select name="country" class="form">
   <option value="0">Please choose:</option>
   <option value="0">___</option>
   <option value="USA">United States</option>
   <option value="England">England</option>
   <option value="Scotland">Scotland</option>
   <option value="Wales">Wales</option>
   <option value="Ireland">Ireland</option>
   <option value="Australia">Australia</option>
   <option value="Canada">Canada</option>
   <option value="0">___</option>
   <option value="Afghanistan">Afghanistan</option>
   <option value="Albania">Albania</option>
   <option value="Algeria">Algeria</option>
<option value="Andorra">Andorra</option>
<option value="Angola">Angola</option>
<option value="Anguilla">Anguilla</option>
<option value="Antigua/Barbuda">Antigua/Barbuda</option>
<option value="Argentina">Argentina</option>
<option value="Armenia">Armenia</option>
<option value="Aruba">Aruba</option>
<option value="Australia">Australia</option>
<option value="Austria">Austria</option>
<option value="Azerbaijan">Azerbaijan</option>
<option value="Bahamas">Bahamas</option>
<option value="Bahrain">Bahrain</option>
<option value="Bangladesh">Bangladesh</option>
<option value="Barbados">Barbados</option>
<option value="Belarus">Belarus</option>
<option value="Belgium">Belgium</option>
<option value="Belize">Belize</option>
<option value="Benin">Benin</option>
<option value="Bermuda">Bermuda</option>
<option value="Bhutan">Bhutan</option>
<option value="Bolivia">Bolivia</option>
<option value="Bosnia">Bosnia</option>
<option value="Botswana">Botswana</option>
<option value="Bouvet Island">Bouvet Island</option>
<option value="Brazil">Brazil</option>
<option value="Brunei">Brunei</option>
</select>
</td>

<? if ($enablefave == 'Y'){ ?>
</tr><tr><td class="small"><?=$whatfave?>:</td>
<td><input type="text" name="fave" size="40" class="form"></td>
<? } ?>
</tr><tr><td>Any comments/questions?</td>
<td><textarea rows="3" name="comments" cols="40" class="form"></textarea>        </td>
</tr><tr colspan="2"><td><div align="center"><input type="submit" name="Subtmit Button" value="Join!" size="30" class="button"><input type="reset" name="Reset Button" value="Don't" size="30" class="button">        </div></td>
</tr></table></form></div>
<br>
<div align="center"><p>Powered by <a href="http://nothing-less.net/Nothing/you/script_fanbase.php" target="_blank">PHPFanBase</a> 2.0</p></div>

<? } elseif ($_POST['action'] == "join"){ 

if (!isset($_POST['name']) || !isset($_POST['email']) ||     !isset($_POST['country'])) {
header( "$siteurl/join.php" );
  } elseif (empty($_POST['name']) || empty($_POST['email']) ||     empty($_POST['country'])) {

echo "<h2>Error</h2><p>Oops, it appears you forgot to enter either your email address, your name or your country. Please press the BACK button in your browser and try again.</P>"; 

} else {

$hideemail = $_POST['hideemail'];
$name = $_POST['name'];
$email = $_POST['email'];
$url = $_POST['url'];
$country = $_POST['country'];
$comments = $_POST['comments'];
$fave = $_POST['fave'];
$apr = $_POST['apr'];

$query="SELECT id FROM $table WHERE email='$email'";
$result=mysqli_query($connect, $query);
$num=mysqli_num_rows($result);

if ($num == "0"){

   if ($emailnotify == 'Y') {

$msg = "Name:\t$name\n";
$msg .= "E-Mail:\t$email\n";
$msg .= "Hide E-Mail:\t$hideemail\n";
$msg .= "URL:\t$url\n";
$msg .= "Country:\t$country\n";
if ($enablefave == 'Y') {
$msg .= "Fave:\t$fave\n";
}
$msg .= "Comments:\t$comments\n";
$msg .= "Sender IP:\t$REMOTE_ADDR\n";
$msg .= "\nLogin to your Admin Panel: $siteurl/admin.php\n";

$recipient = $adminemail;
$subject = "Member - $sitename";
$mailheaders = "From: $email\n";
$mailheaders .= "Reply-To: $email\n\n";

 mail($recipient, $subject, $msg, $mailheaders);
 }

   if ($enablefave == 'Y') {
   $query = "INSERT INTO $table values       ('','$name','$email','$url','$country','$comments','$hideemail','$apr','$fave')";
   } else {
   $query = "INSERT INTO $table values     ('','$name','$email','$url','$country','$comments','$hideemail','$apr')";
 }
 mysqli_query($connect, $query);

echo "<p>Thank you, $_POST[name]! You will be added to the members list with the next update. :)</p>";

} else { ?>
<p>Sorry, but this email address is already listed in the database. This means that you're already listed as a member. If you wish to update your member information, please use the <a href="join.php?action=update">Update Form</a>. If you want to see your listing as a member, please <a href="members.php">click here</a>.</p> 
<? }
}

} elseif ($_GET['action'] == "update"){  ?>
<div align="justify">
<p>Please use the form below to update your member information. If you wish to join this fanlisting, use the Join Form located <a href="join.php">here</a>. Thanks!</p>

<script>
function submitonce(theform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
    if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}
}
</script>

<div align="center"><form method="post" action="join.php" onSubmit="submitonce(this)">
<input type="hidden" name="action" value="sendupdate">
<table border="0" cellspacing="0" cellpadding="2">
<tr><td>Member ID:</td>
<td><input type="text" name="id" size="40" class="form"></td>

</tr><tr><td>Name:</td>
<td><input type="text" name="name" size="40" class="form"></td>

</tr><tr><td>Old Email:</td>
<td><input type="text" name="email" size="40" class="form"></td>

</tr><tr><td>Old URL:</td>
<td><input type="text" name="url" value="http://" size="40" class="form">    </td>

</tr><tr><td>Country:</td>
<td><input type="text" name="country" size="40" class="form"></td>

</tr><tr><td>New Email:</td>
<td><input type="text" name="newemail" size="40" class="form"></td>

</tr><tr><td>New URL:</td>
<td><input type="text" name="newurl" value="http://" size="40" class="form"></td>

</tr><tr><td>Did anything else change?</td>
<td><textarea rows="3" name="comments" cols="40" class="form"></textarea>    </td>
</tr><tr colspan="2"><td><div align="center"><input type="submit" name="Subtmit Button" value="Send!" size="30" class="button"><input type="reset" name="Reset Button" value="Don't" size="30" class="button">    </div></td>
</tr></table></form></div>

<? } elseif ($_POST['action'] == "sendupdate"){  
if (!isset($_POST['name']) || !isset($_POST['email']) ||     !isset($_POST['country'])) {
header( "$siteurl/join.php?update" );
} elseif (empty($_POST['name']) || empty($_POST['email']) ||     empty($_POST['country'])) {

echo "<h2>Error</h2><p>Oops, it appears you forgot to enter either your old email address, your name or your country. Please press the BACK button in your browser and try again.</P>";

} else {

$name = $_POST['name'];
$email = $_POST['email'];
$url = $_POST['url'];
$newemail = $_POST['newemail'];
$newurl = $_POST['newurl'];
$country = $_POST['country'];
$comments = $_POST['comments'];
$fave = $_POST['fave'];
$apr = $_POST['apr'];

$msg = "Name:\t$name\n";
$msg .= "Old E-Mail:\t$email\n";
$msg .= "Old URL:\t$url\n";
$msg .= "Country:\t$country\n";
$msg .= "New E-Mail:\t$newemail\n";
$msg .= "New URL:\t$newurl\n";
$msg .= "Other Changes:\t$comments\n";
$msg .= "Sender IP:\t$REMOTE_ADDR\n";
$msg .= "\nLogin to your Admin Panel: $siteurl/admin.php\n";

$recipient = $adminemail;

$subject = "Update Info - $sitename";

$mailheaders = "From: $email\n";
$mailheaders .= "Reply-To: $email\n\n";

mail($recipient, $subject, $msg, $mailheaders); 
echo "<p>Thanks, your Update has been sent. I will change your information as     soon as possible!</p>";?>

<? } } include("footer.php");?>

【问题讨论】:

  • 你检查过错误日志吗?
  • 是的,脚本可能由于某种原因停止(检查错误日志,或带有ErrorReporting(E_ALL) 的屏幕)
  • 你的意思是没有包含footer.php文件?
  • 错误日志说PHP Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ',' or ';'

标签: php forms email footer


【解决方案1】:

您的代码中某些 echo 之前有语法错误。 在错误日志中检查它中断的行,或者手动跟踪它设置一些打印或转储。 您应该尝试编写更具可读性的代码(缩进,不要混合那么多 html 和 php),因为这是此类错误的主要来源。

它说期望','或';',所以它可能是一个未闭合的数组或函数,或类似的东西。您发布的代码没有显示任何静态错误,因此它可能是动态生成的。

这些,例如:

<? if ($enablefave == 'Y'){ ?>
// stuff
<? } elseif ($_POST['action'] == "join"){ 

这使您的代码很难遵循,因此很难跟踪错误。 你有这样的语法来做到这一点:

<?php if ($a == 5): ?>
A is equal to 5
<?php endif; ?>

http://www.php.net/manual/en/control-structures.alternative-syntax.php

【讨论】:

  • 错误出现在这些行... 313 echo "&lt;h2&gt;Error&lt;/h2&gt;&lt;p&gt;Oops, it appears you forgot to enter either your email address, your name or your country. Please press the BACK button in your browser and try again.&lt;/P&gt;"; 366 &lt;? } } }421 echo "&lt;h2&gt;Error&lt;/h2&gt;&lt;p&gt;Oops, it appears you forgot to enter either your old email address, your name or your country. Please press the BACK button in your browser and try again.&lt;/P&gt;"; 453 echo "&lt;p&gt;Thanks, your Update has been sent. I will change your information as soon as possible!&lt;/p&gt;";?&gt;
  • 可能你在 "$siteurl/join.php" 脚本中留下了一些空标签。
  • 我不确定这是什么意思
  • 我的意思是,join.php 脚本中的一个错误,即您在此处发布的此脚本中产生了一个错误。我的建议是你应该尝试重构你的代码,例如,在关闭 php 标签之前关闭你打开的每个块。我确信此类错误将不再出现。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-07-28
  • 2014-10-27
  • 2023-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多