我完全没有资格去尝试我正在尝试的东西,但直到现在,我的事情似乎还在按我的方式进行。我的函数有一个问题,当单击form按钮时,它似乎没有被调用。如果这是格式错误的,请原谅。请看下面的代码,谢谢
Functions.php
// UP DATE INFO
function settingsUpdate()
{
// call these variables with the global keyword to make them available in function
global $db;
// receive all input values from the form. Call the e() function
// defined below to escape form values
$usernameU = e($_POST['name']);
$numberU = e($_POST['number']);
$id = (isset($_SESSION['user']['id']));
$error = '0';
if($error == 0){
$query = "UPDATE users SET 'username' 'number' WHERE id==$id
VALUES('$usernameU', '$numberU')";
mysqli_query($db, $query);
echo '<div class="alert alert-primary" role="alert">User Settings Updated Successfully.</div>';
} else {
?><div class="alert alert-danger" role="alert">
<p class="text-center"><strong>Oh snap!</strong> Something went wrong, contact us if you think that's wrong.</p>
</div>,<?php
}
}Settings.php
<!--begin::Form-->
<form id="settings" class="form" method="post">
<!--begin::Card body-->
<div class="card-body border-top p-9">
<!--begin::Input group-->
<div class="row mb-6">
<!--begin::Label-->
<label class="col-lg-4 col-form-label required fw-bold fs-6">Full Name</label>
<!--end::Label-->
<!--begin::Col-->
<div class="col-lg-8">
<!--begin::Row-->
<div class="row">
<!--begin::Col-->
<div class="col-lg-6 fv-row">
<input type="text" name="username" class="form-control form-control-lg form-control-solid mb-3 mb-lg-0" placeholder="Full Name" value="<?php echo $username; ?>" />
</div>
<!--end::Col-->
</div>
<!--end::Row-->
</div>
<!--end::Col-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="row mb-6">
<!--begin::Label-->
<label class="col-lg-4 col-form-label fw-bold fs-6">
<span class="required">Contact Number</span>
<i class="fas fa-exclamation-circle ms-1 fs-7" data-bs-toggle="tooltip" title="Phone number must be active"></i>
</label>
<!--end::Label-->
<!--begin::Col-->
<div class="col-lg-8 fv-row">
<input type="number" name="number" class="form-control form-control-lg form-control-solid" placeholder="Phone number" value="<?php echo $_SESSION['user']['number']?>" />
</div>
<!--end::Col-->
</div>
<!--end::Input group-->
</div>
<!--end::Card body-->
<!--begin::Actions-->
<div class="card-footer d-flex justify-content-end py-6 px-9">
<button type="submit" class="btn btn-primary" id="settingsUpdate">Save Changes</button>
</div>
<!--end::Actions-->
</form>
<!--end::Form-->发布于 2021-09-04 13:21:22
在窗体元素中添加action属性
<form id="settings" class="form" method="post" action="Functions.php">
......
</form>在您的Functions.php中创建一个类并将您的函数放入
$settingUp = new SettingUp($_POST['username'], $_POST['number']);
$settingUp->settingsUpdate();
class SettingUp
{
protected $username;
protected $number;
function __construct($username, $number)
{
$this->username = $username;
$this->number = $number;
}
function settingsUpdate()
{
$usernameU = $this->username;
$numberU = $this->number;
$id = (isset($_SESSION['user']['id']));
//complete the rest of your code
}
}您还可以将Functions.php包含在settings.php中,并在提交按钮中指定名称。
<?php
include('Functions.php');
?>
<form id="settings" class="form" method="post" action="">
......
<button type="submit" class="btn btn-primary" id="settingsUpdate" name="settingsUpdate">Save Changes</button>
</form>在Function.php中,删除函数并修改代码,如下所示
if(isset($_POST['settingsUpdate'])
{
$username = $_POST['username'];
$number = $_POST['number'];
//add the rest of your code
}https://stackoverflow.com/questions/69053082
复制相似问题