我正在制作一个测验系统,当我尝试插入问题文本时,从HTML表单的$_POST,它只是插入一个空值,并且question_id保持为零:
Question text: <br />
<textarea name="qtext" rows="2" style="width:200px; height:100px;" name="qst"></textarea> <br />
PHP部分$post_qtext = $_POST['qst'];
$post_qtext = mysql_real_escape_string($post_qtext);
$q_insertquestions = mysql_query("INSERT INTO `questions` (`question`,`type`) VALUES ('$post_qtext','1')");
$q_lastquestioninserted = mysql_insert_id($q_insertquestions);
question_id在表中是int(11)问题在mysql是varchar(60)
textarea有name="qtext"
,而PHP有$_POST['qst'];
。
您需要访问与您的字段名称相同的数组索引。
…我现在看到也有name="qst"
。不允许在一个元素上两次使用相同的属性。浏览器可能会也可能不会从这个错误中恢复。您应该使用验证器
你已经在你的HTML页面上写了两次名字,改变它,也改变你的文本区域名称为qst
<textarea name="qst" rows="2" style="width:200px; height:100px;"></textarea> <br />
因为您为textarea
添加了两个名称
从textarea
中删除name="qst"
<textarea name="qtext" rows="2" style="width:200px; height:100px;"></textarea>
和Do like this:
$post_qtext = $_POST['qtext'];