0

I have a website where users can register, login and do some tasks. I therefore have a special page which shows only when a user has given access to it by the admin (ME). This page has some values which I want to be updated in the database of the current user session. They are six values, and they are not from user inputs, they are values which are ready to be posted when the user clicks the submit button. The user can not see these values.

So far I have managed to guess some codes but they are not making any sense, and when I click the button nothing happens, not even an error.

Okay let me simplify my question. When the logged in user clicks then button, I want these values to be posted to the user's row in the database to the relevant column names (I have already created these in php database). If you check my code below, I want these values/numbers to be posted to the user's row: 1, 2, 3, 4, 5 and 6.

For example if its matt@gmail.com who is logged in, I want when he clicks the button to have those numbers added in relevant columns, check this screenshoot

I have tried this below, but I am sure this is not the best way to do so. When I click the button nothing happens, not even error nor action and nothing is added to the database

    <?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>

My question differs with previously asked ones in such a way that mine is not about taking data from user inputs

Elitte
  • 21
  • 5

0 Answers0