如何在PHP数据库中更新用户详细信息

问题描述

我有一个网站,用户可以在其中注册登录并执行一些任务。因此,我有一个特殊的页面,仅在用户授予管理员(ME)的访问权限时显示。该页面包含一些我想在当前用户会话的数据库中更新的值。它们是六个值,它们不是来自用户输入的,它们是可以在用户单击提交按钮时发布的值。用户看不到这些值。

到目前为止,我已经设法猜出了一些代码,但是它们没有任何意义,当我单击按钮时,什么也没有发生,甚至没有错误

好的,让我简化我的问题。当登录用户单击“然后”按钮时,我希望将这些值发布到数据库用户行的相关列名(我已经在PHP数据库中创建了这些值)。如果您在下面查看我的代码,我希望将这些值/数字发布到用户行:1、2、3、4、5和6。

例如,如果登录用户[email protected]想要在他单击按钮时将这些数字添加到相关列中,请选中此

screenshoot

我已经在下面尝试过了,但是我确信这不是最好的方法。当我单击按钮时,什么也没有发生,甚至没有错误也没有采取行动,什么也没有添加数据库

    <?PHP
//all errors
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);

// Initialize the session
session_start();

// Check if the user is logged in,otherwise redirect to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
    header("location: login.PHP");
    exit;
}
 
// Include config file
require_once "config.PHP";

 
// Define variables and initialize with empty values
$investment = $cleared = $balance = $refnumber = $refbalance = $monthgain = "";
 
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
 
 // Prepare an update statement
        $sql = "UPDATE users SET (investment,cleared,balance,refnumber,refbalance,monthgain) VALUES (?,?,?) WHERE id = ?";
        
        if($stmt = MysqLi_prepare($link,$sql)){
            // Bind variables to the prepared statement as parameters
            MysqLi_stmt_bind_param($stmt,"ssssssi",$param_investment,$param_cleared,$param_balance,$param_refnumber,$param_refbalance,$param_monthgain,$param_id);
            
            // Set parameters
            $param_id = $_SESSION["id"];
            $param_investment = 1;
            $param_cleared = 2;
            $param_balance = 3;
            $param_refnumber = 4;
            $param_refbalance = 5;
            $param_monthgain = 6;
            
            // Attempt to execute the prepared statement
            if(MysqLi_stmt_execute($stmt)){
                /* store result */
                MysqLi_stmt_store_result($stmt);

                    // Redirect to dashboard page
                header("location: dashboard.PHP");
                
            } else{
                echo "Oops! Something went wrong. Please try again.";
            }
            
            // Close statement
            MysqLi_stmt_close($stmt);
        }
    
    // Close connection
    MysqLi_close($link);
}
?>


<!doctype html>
<html lang="en">
<head>
    <Meta charset="UTF-8">
    <title>Signup</title>
    <style>
        body{
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
    <div class="contact-form">
        <img src="img/2.jpg" class="avatar">
        <h2>Update</h2>
        <form method="post" action="<?PHP echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
            
            <input type="submit" name="" value="UPDATE DETAILS">
        </form>
    </div>
</body>
</html>

我的问题与先前提出的问题不同,我的问题不是关于从用户输入中获取数据

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)