2013-06-20 37 views
0

我遇到了textarea post值有時無法處理的問題。問題是,間歇性地我錯過了textarea 27和30的一些值。它似乎不是瀏覽器問題,它似乎不是數據長度的問題。處理POST時有時缺少textarea值

這是HTML表單:

<div id="surveycontainer"> 
     <form method="POST" action="blog/questions" name="exitform"> 
     <input id="pnum" type="hidden" name="pagenum" value="3"/> 

     <div class="qsection"> 
     <p> 
      27. Suppose that a friend from another nation comes to see you and doesn’t know about the U.S. economy. How would you <span style="font-style:italic">describe the economy</span> to your friend? Please actually write the words you would say as specifically as possible. 
     </p> 
     <textarea id="mlq1" name="27" cols="50" rows="5"></textarea> 
     </div> 

     <div class="qsection"> 
     <p> 
      28. What is your opinion about the future of the U.S. economy? Do you think that over the next few months the U.S. economy will improve, become worse, or stay the same? 
     </p> 
      <input type="radio" name="28" value="-2"><span class="radiotext">-2 (Greatly worse)</span><br/> 
      <input type="radio" name="28" value="-1"><span class="radiotext">-1 (Worse)</span> <br/> 
      <input type="radio" name="28" value="0"><span class="radiotext">0 (Stay the same)</span> <br/> 
      <input type="radio" name="28" value="1"><span class="radiotext">1 (Better)</span> <br/> 
      <input type="radio" name="28" value="2"><span class="radiotext">2 (Much better)</span> 
     </div> 

     <div class="qsection"> 
     <p> 
      29. What are the reasons for your prediction? Explain or list them. 
     </p> 
     <textarea id="mlq2" name="29" cols="50" rows="5"></textarea> 
     </div> 

     <div class="qsection"> 
     <p> 
      30. What do you suggest as a solution to improve the U.S. economy? 
     </p> 
     <textarea id="mlq3" name="30" cols="50" rows="5"></textarea> 
     </div> 

這裏是處理PHP:

private function processAnswers($pid) 
    { 
    date_default_timezone_set('America/Chicago'); 
    $created = date("Y-m-d H:i:s"); 

    foreach($_POST as $key=>$value) { 
     if ($key == "pagenum") 
     continue; 
     // echo "$key: $value \n"; 
     $sql = "insert into default_answers (participant_id, answer_id, answer_value, created) values (" . $pid . ",'" . htmlspecialchars($key) . "','" . htmlspecialchars($value) . "', '" . $created . "')"; 
     // echo $sql; 
     $this->db->query($sql); 
    } 
    } 

這是調用它的代碼:

if (isset($_POST['pagenum'])) { 
    $pagenum = $this->input->post('pagenum'); 

    $this->processAnswers($pid); 
} 

感謝

+1

你看到了什麼錯誤?數據庫偶爾會缺少這些行的值?這可能表明輸入沒有正確轉義的問題。 –

+1

您確定這些'