2011-07-21 96 views
0

如標題所示,我有一個頁面供用戶創建項目,另一個頁面將其添加到我的數據庫中。但是,當我按下提交表單域爲空時,它發佈的頁面不是空白的。但是,當我填寫的字段提交時,它只是顯示一個沒有任何錯誤的空白頁面,我瀏覽了兩頁代碼,但似乎找不到任何錯誤。也許這裏有人可以幫助我?謝謝。空白頁按下提交按鈕後,所有字段填滿

//在提交數據的頁面上的代碼。

if ($_POST['projectTitle'] != "" && $_POST['projectStatus'] != "" && $_POST['projectDesc'] != "" && $_POST['projectDeliv'] != "" && $_POST['year'] != "" && $_POST['month'] != "" && $_POST['day'] != "" && $_POST['projectSS'] != "") { 

     $host = "localhost"; 
     $user = "root"; 
     $pass = ""; 
     $db = "fyp1"; 

     $pt = $_POST['projectTitle']; 
     $ps = $_POST['projectStatus']; 
     $pdes = $_POST['projectDesc']; 
     $pdel = $_POST['projectDeliv']; 
     $date = $_POST['year'] . "-" . $_POST['month'] . "-" . $_POST['day']; 
     $pss = $_POST['projectSS']; 
     date_default_timezone_set('UTC+8'); 
     $cDate = date('Y-m-d'); 
     $uid = $_SESSION['id']; 

     $link = mysqli_connect($host, $user, $pass, $db) or die(mysqli_error()); 
     $query = "SELECT * FROM project WHERE project_title = $pt AND project_description = $pdes AND project_deliverables = $pdel AND project_skillset = $pss"; 
     $dub = mysqli_query($link, $query) or die(mysqli_connect_error($link)); 

     if (mysqli_num_rows($dub) == 0) { 

      $insertQ = "INSERT INTO project(project_title,project_description,project_deliverables,project_start,project_end,project_skillset,project_status) 
       VALUES ('$pt','$pdes','$pdeliv','$cDate','$date','$pss',$ps)"; 
      mysqli_query($link, $insertQ) or die(mysqli_connect_error($link)); 

      $getPID = "SELECT * FROM project WHERE project_title = $pt AND project_description = $pdes AND project_deliverables = $pdel AND project_start = $cDate AND projecct_end = $date AND project_skillset = $pss"; 
      $pid = mysqli_query($link, $getPID) or die(mysqli_connect_error($link)); 
      if (mysqli_num_rows($pid) == 1) { 
       while ($row = mysqli_fetch_array($pid)) { 
        $proid = $row['project_id']; 
        $insertF = "INSERT INTO user_has_project(user_id,project_id) VALUES ('" . $uid . "','" . $proid . "')"; 
        mysqli_query($link,$insertF) or die(mysqli_connect_error($link)); 
        $message = "<p>Project Successfully Added!</p>"; 
        $message .= "<a href='index.php'>Back</a>"; 
        $a = true; 
       } 
      } else { 
       $message = "<p>Project Failed To Be Added!</p>"; 
       $message .= "<a href='createProject.php'>Back</a>"; 
       $a = false; 
      } 
     } else { 
      $message = "<p>Duplicate Project Found!</p>"; 
      $message .= "<a href='createProject.php'>Back</a>"; 
      $a = false; 
     } 
    } else { 
     $message = "<p>Please Fill Up All Fields When Creating A Project!</p>"; 
     $message .= "<a href='createProject.php'>Back</a>"; 
     $a = false; 
    } 

//與形式

<div id="content"> 
     <?php if ($a == false) { 
     ?> 
       <h2 id="registerFont">Create Project</h2> 
       <form name="createProject" method="post" action="doCreateProject.php" onSubmit="return validateForm(this);"> 
        <fieldset> 
         <table> 
          <tr> 
           <th colspan="4"><h2>New Project</h2></th> 
          </tr> 
          <tr> 
           <th colspan="4"><hr /></th> 
          </tr> 
          <tr> 
           <td><label for="projectTitle">Project Title:</label></td><td><input name="projectTitle" type="text" /></td> 
           <td><label for="projectStatus">Project Status:</label></td> 
           <td><select name="projectStatus"> 
           <?php while ($row = mysqli_fetch_array($result1)) { 
           ?> 
            <option value="<?php echo $row['status_id']; ?>" ><?php echo $row['status_type']; ?></option> 
           <?php } ?> 
          </select></td> 
        </tr> 
        <tr> 
         <td><label for="projectDesc">Project Description:</label></td><th colspan="3"><textarea name="projectDesc" rows="5" cols="40" ></textarea></th> 
        </tr> 
        <tr> 
         <td><label for="projectDeliv">Project Deliverables:</label></td><th colspan="3"><textarea name="projectDeliv" rows="5" cols="40" ></textarea></th> 
        </tr> 
        <tr> 
         <td>Start Date:</td><td><?php echo $date; ?></td> 
        </tr> 
        <tr> 
         <td>End Date : </td> 
         <th colspan="3" align="left"> 
          <select name="year"> 
           <option>---Year---</option> 
           <?php for ($i = $cYear; $i < ($cYear + 100); $i++) { 
           ?> 
            <option value="<?php echo $i; ?>"><?php echo $i; ?></option> 
           <?php } ?> 
          </select> 
          <select name="month"> 
           <option>---Month---</option> 
           <?php while ($rows = mysqli_fetch_array($result)) { 
           ?> 
            <option value="<?php echo $rows['month_id']; ?>"><?php echo $rows['month']; ?></option> 
           <?php } ?> 
          </select> 
          <select name="day"> 
           <option>---Day---</option> 
           <?php for ($i = 1; $i < 32; $i++) { 
           ?> 
            <option value="<?php echo $i ?>"><?php echo $i ?></option> 
           <?php } ?> 
          </select> 
         </th> 
        </tr> 
        <tr> 
         <td><label for="projectSS">Project Skill Set:</label></td><td><input name="projectSS" type="text"/></td><th colspan="2"><small>(Please Separate By Comma)</small></th> 
        </tr> 
       </table> 
      </fieldset> 
      <br /> 
      <input name="submit" type="submit" value="Create Project" /> 
     </form> 
     <?php 
          } else { 
           echo $message; 
          } 
     ?> 
         </div> 
+0

你能發表一些代碼嗎?特別是您要發佈到的頁面。 – wanovak

+2

我認爲你的代碼有錯誤,錯誤報告已關閉 – k102

+1

歡迎使用SQLi!歡迎來到我們的網站! – genesis

回答

0

頁上的代碼,我設法解決這個問題。在查詢數據庫時,在我的SELECT語句中,我忘記添加的變量「'。例如,SELECT * FROM project WHERE project_title ='$ variable';

反正。感謝那些幫助過的人。對此,我真的非常感激。

相關問題