[英]Add new SQL record, taking ID from current php?id=
我意识到我可能是有史以来最大的菜鸟,但这使我整日生气……
因此,基本上,我有1个名为“ clients”的表,其中包含基本的客户详细信息...我已经管理好search.php,view.php和edit.php以显示和编辑客户搜索结果,但是我想要一个“链接到newproject.php的每个搜索结果下方的“添加项目”按钮,将当前正在查看的客户端ID填充到表单中,因此我可以使用客户端的详细信息“创建新项目”,而不必将其放入再次-我整天都尝试了不同的尝试,但都无济于事,而现在我很想念最基本的解决方案!
任何帮助将非常感谢!
// connect to the database
include('connect-db.php');
// get results from database
$result = mysql_query("SELECT * FROM clients")
or die(mysql_error());
// display data in table
echo "<p><b>View All</b> | <a href='view-paginated.php?page=1'>View Paginated</a></p>";
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['ID'] . '</td>';
echo '<td>' . $row['Title'] . '</td>';
echo '<td>' . $row['LastName'] . '</td>';
echo '<td><a href="edit.php?id=' . $row['ID'] . '">Edit</a></td>';
echo '<td><a href="delete.php?id=' . $row['ID'] . '">Delete</a></td>';
echo "</tr>";
}
// close table>
echo "</table>";
是view.php
$sql="INSERT INTO projects (projectname, budget)
VALUES
('$_POST[projectname]','$_POST[budget]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
是insertproject.php
<form action="insertproject.php" method="post">
Project Name: <input type="text" name="projectname" /><br><br>
Budget: <input type="text" name="budget" /><br><br>
是newproject.php
出于某种原因,我想出了一个主意,即我希望一个预填充了URL中GET ID的文本框直接进入项目表单...
如果对您来说,这听起来比对我来说简单,那么您应该获得诺贝尔奖!
将client_id传递到newproject.php
,并将client_id
收集在newproject.php
,然后将值放在表单内的隐藏字段中。
在搜索结果页中添加
<a href="newproject.php?client_id=<?php echo $clientID; ?>">Add Project </a>
在newproject.php页面中
<?php
$clientId = $_REQUEST['client_id']
?>
<form method="post" action="newproject.php">
<input type="hidden" name="client_id" id="client_id" value="<?php echo $clientId;?>"/>
-----------------
Your Project Form
-----------------
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.