我正在尝试进行一次小型调查,以填充数据库名称列表中下拉菜单的选择.调查可以正确执行此操作.我想将用户使用此名称提交的报价提交到报价数据库中.他们在字段中输入的引号文本可以正确输入,但是,菜单中选择的名称未传递.相反,我得到了一个空白的名称字段.
我了解我的一些代码是在上下文之外的,但是名称是唯一没有正确传递的东西.
在表单提交上,我包括将此数据提交到数据库的php文件:
" method="post">
What did they say?:
变量$name来自此(填充我的下拉菜单):
echo "";
while ($temp = mysql_fetch_assoc($query)) {
echo "".htmlspecialchars($temp['name'])."";
}
echo "";
这是我的formsubmit.php:
mysql_select_db('quotes');
if (isset($_POST['quotetext'])) {
$quotetext = $_POST['quotetext'];
$ident = 'yankees';
$sql = "INSERT INTO quote SET
quotetext='$quotetext',
nametext='$name',
ident='$ident',
quotedate=CURDATE()";
header("Location: quotes.php");
if (@mysql_query($sql)) {
} else {
echo '
Error adding quote: ' .
mysql_error() . '
';}
}
?>
解决方法:
您的表单操作内容看起来很奇怪,但是无论如何,我认为您遇到的问题与不像设置$quotetext = $_POST [‘quotetext’]一样设置$name = $_POST [‘name’]有关.在sql语句之前执行此操作,应该很好.
编辑以尝试进一步帮助您,我将包括代码的整体结构,并应对其进行调整以适合您的实际代码(无论遗漏什么,例如为名称选项设置$query) :
文件1:
What did they say?:
while ($temp = mysql_fetch_assoc($query)) {
echo "".htmlspecialchars($temp['name'])."";
}
?>
formsubmit.php:
mysql_select_db('quotes');
if (isset($_POST['quotetext'])) {
$quotetext = $_POST['quotetext'];
$name = $_POST['name'];
$ident = 'yankees';
$sql = "INSERT INTO quote SET
quotetext='$quotetext',
nametext='$name',
ident='$ident',
quotedate=CURDATE()";
if (@mysql_query($sql)) {
header("Location: quotes.php");
} else {
echo '
Error adding quote: ' .
mysql_error() . '
';}
}
?>
标签:html,mysql,php
来源: https://codeday.me/bug/20191208/2090362.html