2013-07-12 32 views
0

我试过寻找这个问题,但我似乎无法弄清楚。表单显示没有错误,但在谷歌浏览器上,当我尝试提交表单时,它只是说“服务器错误”。表单提交给我一个服务器错误

<?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>'; 
    } 
} 

?> 

也许是因为我不能有指向本身(如果我使用的方法=“获取”行动第一种形式。

+1

查看您的服务器的错误日志。 –

+0

对不起,我对php很陌生,你会如何处理? –

+1

@JohnSmith定义的'PrepSQL()'函数在哪里? – MrCode

回答

0

你似乎并没有定义的PrepSQL()任何地方。如果这是你应该得到一个致命的错误的情况下,像

Fatal error: Call to undefined function PrepSQL ...

一旦这样固定的,如果你插入查询失败,它可能会因为缺少封闭引号值。

以便将来调试,你可以打开错误:

error_reporting(E_ALL); 
ini_set('display_errors', '1'); 

或者,你可以观察你的服务器的错误日志。如何完成取决于服务器设置,因此我建议询问主机的方向。

旁注:

  • mysql_*库已过时,可以考虑升级到PDO或MySQLi的
  • 一个Prepared Statement的使用最好串联变量到SQL。