gpt4 book ai didi

PHP 使用 HTML 表单更新 MySQL 表

转载 作者:行者123 更新时间:2023-11-30 22:14:54 24 4
gpt4 key购买 nike

我正在尝试使用 HTML 页面中的表单来更新我的 MySQL 表。

这是我的 PHP 代码

    <?php
ob_start();
session_start();
require_once 'dbconnect.php';

if( !isset($_SESSION['client']) ) {
header("Location: homepage_login.php");
exit;
}
// select loggedin users detail
$res=mysql_query("SELECT * FROM clients WHERE client_id=".$_SESSION['client']);
$userRow=mysql_fetch_array($res);

if( isset($_POST['btn-book']) ) {

$sql="UPDATE appointments SET date='$slot_date', line='$slot_line', reason='$reason' WHERE id='$id'";
$result=mysql_query($sql);

if($result){
echo "Successful";
}

else {
echo "ERROR";
} }

?>

还有我的 HTML 表单

<form action"" method"post">

<p>Date: <input type="text" id="datepicker" name="date"></p>

<br>
<br>
Select a line:
<ol id="selectable" name="line">
<li class="ui-widget-content">Line 1</li>
<li class="ui-widget-content">Line 2</li>
<li class="ui-widget-content">Line 3</li>
<li class="ui-widget-content">Line 4</li>
<li class="ui-widget-content">Line 5</li>
<li class="ui-widget-content">Line 6</li>
<li class="ui-widget-content">Line 7</li>
</ol>
<br>
<br>

<p>Reason for appointment: <input type="text" name="reaosn"></p>

<div class="form-group">
<button type="submit" class="btn btn-block btn-primary" name="btn-book">Book</button>
</div>

</form>

顺便说一句,这些都在同一页上。所以我需要做的是,当有人填写表单并点击提交按钮时,PHP 代码将更新我的 MySQL 表中已创建的特定记录。

我不确定我是否需要以某种方式指定我要更新的记录,或者我是否完全搞砸了实际更新我的表。

所以,我的问题是:

如何使用 HTML 表单和 PHP 代码更新表格中的特定记录?

最佳答案

只需回显表单上的所有值

例如:<p>Date: <input type="text" id="datepicker" name="date"></p>进入<p>Date: <input type="text" id="datepicker" value="<?php echo $result['date']; ?> " name="date"></p>

关于PHP 使用 HTML 表单更新 MySQL 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38738618/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com