如何更改以下代码以允许我从其他表格(data2)中提取数据,并将其作为其他人员(姓名,职位,生物)进行发布。基本上我想要另一个表单域,我可以从另一个表中找到一个项目,然后添加到这个项目中。SQL PHP可搜索表格字段添加到新数据库
<?php
require 'db/connect.php';
$error = ""; //variable to hold our form error message
$success = ""; //variable to hold our success message
if(isset($_POST['create'])){
$name = trim($_POST['name']);
$position = trim($_POST['position']);
$bio = trim($_POST['bio']);
if(empty($name) && empty($position) && empty($bio)){
$error = "You must fill all fields.";
}else{
$insert = $db->prepare("INSERT INTO staff (name, position, bio, joined) VALUES (?, ?, ?, NOW())");
$insert->bind_param(sss, $name, $position, $bio);
if($insert->execute()){
//$success = "Staff added successfully!";
header("location:index.php");
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="wrapper">
<h1>Create New Staff</h1>
<span class="error"><?php if(isset($error)) echo $error;?></span>
<span class="success"><?php if(isset($success)) echo $success;?> </span>
<form action="" method="post">
<table class="table">
<tr>
<td><label for="name">Name:</label></td>
<td><input type="text" id="name" name="name"></td>
</tr>
<tr>
<td><label for="position">Position:</label></td>
<td><input type="text" id="position" name="position"></td>
</tr>
<tr>
<td><label for="bio">Bio:</label></td>
<td><textarea id="bio" name="bio"></textarea></td>
</tr>
<tr>
<td></td>
<td><button type="submit" class="create" name="create">CREATE</button> <a class="btn" href="index.php">BACK</a></td>
</tr>
</table>
</form>
</div>
</body>
</html>
您可以使用jQuery的自动完成功能。或者你可以参考这里:http://stackoverflow.com/questions/21298169/autocomplete-textbox-results-based-from-sql-database – 2015-03-31 02:06:43
请你可以裁剪你的形象到必要的部分?因为它使内容更长,没有一个合理的原因 – dvhh 2015-03-31 03:26:21