0

我有时会遇到无法处理 textarea 帖子值的问题。问题是我间歇性地丢失了 textarea 27 和 30 的一些值。这似乎不是浏览器问题,也不是数据长度问题。

这是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);
}

谢谢

4

1 回答 1

0

谢谢Mock Daear,就是这样。mysql_real_escape_string(htmlspecialchars)。当输入中有一个单引号时,就会发生这种情况。

于 2013-06-21T01:12:13.510 回答