Php 表单提交给我一个服务器错误

Php 表单提交给我一个服务器错误,php,sql,forms,submit,Php,Sql,Forms,Submit,我试过寻找这个问题,但似乎找不出答案。表单显示时没有错误,但在谷歌浏览器上,当我尝试提交表单时,它只会显示“服务器错误” <?php if (empty($_GET["entries"])) //check if the admin entered # of weeks { ?> <p>How many weeks do you want to make? </p> <form action="" method="get"> <

我试过寻找这个问题,但似乎找不出答案。表单显示时没有错误,但在谷歌浏览器上,当我尝试提交表单时,它只会显示“服务器错误”

<?php 
if (empty($_GET["entries"])) //check if the admin entered # of weeks
{ 
?>

<p>How many weeks do you want to make? </p>
<form action="" method="get">
    <input type="text" name="entries" placeholder="Number of weeks" />
    <br/>
    <input type="submit" name="submit_entries" />
</form>

<?php 
}
else
{
    //Second form
    if (isset($_POST["submit"])) //check if submitted
    {
        //Process form
        $entries=$_GET['entries'];
        $newWeeks=$_POST['week'];
        $db= mysql_connect("localhost", "root", "root");
        if(!$db) die("Error connecting to MySQL database.");
        mysql_select_db("onlineform", $db);

       $sql = "INSERT INTO onlineformdata (numberOfWeeks, newCampSessions) VALUES (" . PrepSQL($entries) . "," . PrepSQL($newWeeks) . ")";

        mysql_query($sql);
        if (mysql_query($sql) === FALSE) {
        die(mysql_error());
        }
        mysql_close();
    }
    else //if not submitted yet, show the form
    {
        echo '<form action="" method="post">';

        for ($count = 0; $count < $_GET["entries"]; $count++)
        {
            echo  'Enter a beginning to ending date for the week: <input type="text" name="week"><br/>';
        }

        echo '<input type="submit" name="submit"></form>';
    }
}

?>

你想定几周



您似乎没有在任何地方定义
PrepSQL()
。如果是这样的话,你应该得到一个致命的错误,比如

致命错误:调用未定义的函数PrepSQL

一旦修复了这个问题,如果您的insert查询失败,很可能是因为缺少括引号的值

对于将来的调试,可以启用错误:

error_reporting(E_ALL);
ini_set('display_errors', '1');
或者,您可以只查看服务器的错误日志。如何做到这一点取决于服务器设置,因此我建议询问您的主机的方向

旁注:

    <>代码> MySqL**<代码>库被禁止,考虑升级到PDO或MySQL LI/LI>
  • 与将变量连接到SQL中相比,最好使用

查看您服务器的错误日志。对不起,我对php非常陌生,您将如何准确地处理此问题?@JohnSmith哪里定义了
PrepSQL()
函数?谢谢,我想就是这样。在第二种形式中,您将有多个同名输入。”一周