HOF提名表

时间:2014-04-28 06:46:44

标签: php sql forms

早上好:

我在我的网站上设有一个名人堂,允许访客通过表格提交被提名者。我希望将表单数据提交到另一个页面/ MySQL数据库。这就是我到目前为止所拥有的:

HTML表单页面rebootwwehof.html

<!DOCTYPE html>
<HTML>
<HEAD>
<TITLE>WWE Hall of Fame</TITLE>
</HEAD>
<BODY BGCOLOR=#000000 LINK=#FFFFFF VLINK=#FFFFFF>
<FONT FACE="Arial" COLOR=#FFFFFF>
<BR>
<BR>
<P>It's been said that no Hall of Fame is perfect and certainly the WWE Hall of Fame has gotten its share of criticisms.
However, with this project, I am rebooting the WWE Hall of Fame and inviting people to 
create the perfect WWE Hall of Fame with nominations and votings. On this page, you can submit
individuals (whether wrestlers, managers, referees, announcers, promoters) worthy of induction. The names 
receiving the most nominations will form the initial ballot. There will be two rounds of voting. Nominees 
must receive at 75% of votes to move on the next round. Anyone receiving at 
least 70% but less than 75% will be included on next year's ballot. The 
nomination period will last from April 15 to June 15.
<BR>
<BR><B>Criteria</B>
<BR>
<UL>
<LI>Work (as wrestler, manager, announcer, staff or promoter) for WWE any period from its beginning as Capitol Wrestling Corporation (CWC) days to modern day WWE</LI>
<LI>Drawing power, merchandise sales, achievement</LI>
<LI>Influence or significance in WWE history</LI>
<LI>Age of at least 50 years</LI>
  <UL>
  <LI><B>Exception:</B> being deceased for at least two and a half years 
  </UL>
</UL>
</P> 
<BR>
<BR>
<P>Make your nominations in the form below</P>
<FORM NAME="input" ACTION="http://mvwres.awardspace.us/almanac/rebootwwenominees.php" METHOD="post">
<P>E-mail:<BR> <?PHP ECHO $_POST['email']; ?><INPUT TYPE="text" NAME="email"></P>
<P>Nominees:<BR> <?PHP ECHO ($_POST['nominee']); ?><TEXTAREA NAME="nominees" ROWS="10" COLS="40">
</TEXTAREA></P>
<INPUT TYPE="submit" VALUE="Submit"><INPUT TYPE="reset" VALUE="Reset">
</FORM> 
</BODY>
</HTML>

这是处理数据的网页rebootwwenominees.php:

    <HTML>
    <BODY>

<HEAD>
<TITLE>WWE Hall of Fame Nominations</TITLE>
</HEAD>

    <? 
     $email = $_POST['email']; 
     $nominee = $_POST['nominee'];
     mysql_connect("fdb2.awardspace.com", "mvwi1_newwwehof", "konc!abr") or die(mysql_error()); 
     mysql_select_db("mvwi1_newwwehof") or die(mysql_error()); 
     mysql_table = 'WWE_HOF_Nominator';
     mysql_query("INSERT INTO `data` VALUES ('$email', 'nominee')"); 
     Print "Your information has been successfully added to the database."; 
     ?> 

    </BODY>
    </HTML>

我错过了什么吗?

好的,我已经更新了我的代码并且仍然存在问题(虽然介于两者之间长时间休息)。我在$ con行上一直遇到意外的T_string错误。

<?php
$servername = "sql204.byethost9.com";
$username = "b9_18261515";
$password = "brother1";
$dbname = "b9_18261515_mockwwe";
// Create connection
$con = mysqli_connect("sql204.byethost9.com", "b9_18261515", "brother1", "b9_18261515_mockwwe");
// Check connection

if (!$con) {
    die("Connection failed: " . mysqli_connect_error());
}

mysqli_select_db($con,"b9_18261515") or die ("no database");
$sql = "INSERT INTO WWE_HOF_Nominator (email, nominees) VALUES ('$email', '$nominees')";

if (mysqli_query($con, $sql)) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($con);
}

mysqli_close($con);
?>

1 个答案:

答案 0 :(得分:0)

不确定究竟是什么错误但乍一看你可能会遗漏一些事情:

  1. 像用户3383116所说,有一个错字,被提名人与被提名人

  2. 如果您要使用short_open_tag=On来启动脚本而不是<?,请确保您在php.ini中设置<?php 。请参阅How to enable PHP short tags?

  3. 看起来像这些行:

    mysql_table = 'WWE_HOF_Nominator';
    mysql_query("INSERT INTO `data` VALUES ('$email', 'nominee')"); 
    

    应该是(假设&#34; WWE_HOF_Nominator&#34;是表名和&#34;电子邮件&#34;&#34;被提名者&#34;是列名:

    $mysql_table = 'WWE_HOF_Nominator';
    $query = sprintf("INSERT INTO %s (email, nominee) VALUES (%s, %s)", 
                     mysql_real_escape_string($mysql_table),
                     mysql_real_escape_string($email),
                     mysql_real_escape_string($nominee));
    $result = mysql_query($query);
    if (!$result) {
        die('Invalid query: ' . mysql_error());
    }
    
  4. 您应该在此特定脚本中执行的最后一项操作是关闭数据库连接:

    $link = mysql_connect("fdb2.awardspace.com", "mvwi1_newwwehof", "konc!abr") or die(mysql_error()); 
    
    ...
    
    mysql_close($link);
    ?>
    
  5. http://php.net/manual/en/有很多很好的参考资料和例子。

    希望有所帮助。