将表1中的值输入下拉菜单,然后输入新的mySql表


Values from table1 into drop-down menu and then into new mySql table

我是PHP新手,有点拘泥于我的任务。

我必须将表1中的值输入到下拉菜单中,然后再输入到表2中。

目前,我将这些值放入下拉菜单中,并可以从中进行选择,但是当我将值添加到表2中时,我只得到表1的ID号。我在phpMyadmin中看到了这些,如果我呼应它们的话。

表1名称:人。列:ID、名字、姓氏表2名称:问题。列:ID,名字(来自表1),姓氏(来自表一,问题.

到目前为止我的代码:

<html>
<head>
<title>
</title>
</head>
<?php  
include("yhendus.php");
mysql_query( "SET NAMES utf8" );
$humans = "SELECT * FROM people";
$result = mysql_query($humans) or die(mysql_error());
while($row = mysql_fetch_assoc($result))
{
    $human_id .= "<option value='{$row['id']}'.{$row['firstname']}' . '{$row['surname']}'>{$row['firstname']} {$row['surname']}</option>";
} 
if ($_REQUEST[Send]=="Send")
{
include("yhendus1.php"); // there are 2 connection files, but is works fine
$abi7="insert into questions (id,firstname,surname,question) values 
('$_POST[id]','$_POST[user]','$_POST[user]','$_POST[question]')";
mysql_query($abi7);
}
 ?>
<body>
<form method="POST" action="kysimused.php">
Pick name:<select name="user"><? echo $human_id; ?></select> <br/><br/>
Question:<br/><br/><input type="text" name="question"> <br/><br/>
<br><br/>
<input type="submit" name="Send" value="Send">
</form>
</body>
</html>

希望有人能帮忙!

提前感谢!

首先检查您是否在POST中获得了正确的值,然后尝试打印sql查询并在phpmyadmin中运行该查询。。你会知道错误到底在哪里。

此外,如果mysql中user和question的数据类型是varchar,那么您需要将该值作为字符串传递,即在mysql查询中以双qoutes形式传递。

感谢

相关文章: