我试图找出一种方法来预先填写表格,其中包含过去提交过去表格信息的数据。
我有一个表单和一个数据库。在我的表单中,我有一个名为email
的输入,其中包含预先加载的默认值,即登录成员的只读电子邮件地址。
PIC
http://oi57.tinypic.com/2iubb4j.jpg
如何在下拉菜单中生成一个选项,选中后会从表格中预先填充包含行/记录数据的表单?
如何只生成与表单输入值匹配的记录' email'在'电子邮件'下的具有相同价值的记录数据库中的列?
我已经参与了几个星期了,似乎无法找到任何关于如何实现这一目标的方向。无法找到任何教程网站,视频,示例代码或其他任何关于如何实现这一目标的内容。任何帮助都会很棒......感谢您的帮助。
FORM
</header>
<body>
<form action="/demoform/contact_form.php" class="well" id="contactForm" method="post" name="sendMsg" novalidate="">
<big>LOAD PAST ORDERS:</big>
<select id="extrafield1" name="extrafield1">
<option value="">Please select...</option>
<option value="xxx">SAMPLE SELECTION</option>
</select>
</br>
<input type="text" required id="mile" name="mile" placeholder="Miles"/>
</br>
<input id="email" name="email" placeholder="Email" required="" type="text" value="demo@gmail.com" readonly="readonly"/>
</br>
<input id="name" name="itemname" placeholder="ITEM NAME 1" required="" type="text" />
</br>
<input type="reset" value="Reset" />
<button type="submit" value="Submit">Submit</button>
</form>
</body>
</html>
PHP文件
<?php
define('DB_NAME', 'xxx');
define('DB_USER', 'xxx');
define('DB_PASSWORD', 'xxx');
define('DB_HOST', 'xxx');
$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$connection){
die('Database connection failed: ' . mysqli_connect_error());
}
$db_selected = mysqli_select_db($connection, DB_NAME);
if(!$db_selected){
die('Can\'t use ' .DB_NAME . ' : ' . mysqli_connect_error());
}
echo 'Connected successfully';
if (isset($_POST['itemname'])){
$itm = $_POST['itemname'];
}
else {
$itm = '';
}
if($_POST['mile']){
$mi = $_POST['mile'];
}else{
echo "Miles not received";
exit;
}
if($_POST['email']){
$email = $_POST['email'];
}else{
echo "email not received";
exit;
}
$sql = "INSERT INTO seguin_orders (itemname, mile, email)
VALUES ('$itm', '$mi', '$email')";
if (!mysqli_query($connection, $sql)){
die('Error: ' . mysqli_connect_error($connection));
}
更新:到目前为止最接近的事情......但不会工作......不确定它是否涵盖了匹配的电子邮件值部分...感谢无论如何&#39; edcoder&#39;
<select id="extrafield1" name="extrafield1">
<option value="">Please select...</option>
<?php
$query='select * from tablename';
$res=mysql_query($query);
while($row=mysql_fetch_array($res))
{
?>
<option value="<?php echo $row['feildname']; ?>"><?php echo $row['feildname']; ?></option>
<?php
}
?>
</select>
答案 0 :(得分:0)
好像你差点就到了。
试试这个。
<select id="extrafield1" name="extrafield1">
<option value="">Please select...</option>
<?php
$email = $_POST['email'];
$query="select * from tablename WHERE email={$_POST['email']}";
$res=mysqli_query($connection,$query);
while($row = mysqli_fetch_assoc($res))
{
?>
<option value="<?php echo $row['fieldname']; ?>"><?php echo $row['fieldname']; ?></option>
<?php
}
?>
</select>