Home » Php » Recording data from a session into a database and reading the same log file

Recording data from a session into a database and reading the same log file

Posted by: admin October 26, 2017 Leave a comment

Questions:

I’ve been trying to solve this problem for two days, and if someone can advise me, I would be grateful.

I recorded an id from another server in the wp database, and I want to read that id again this time when logging in, this is my input for that user_id

    <?php
if(isset($_SESSION['user_id'])){
    $user_id = $_SESSION['user_id'];
    $email = $_SESSION['user_email'];


    /* Attempt MySQL server connection. Assuming you are running MySQL
    server with default setting (user 'root' with no password) */
    $link = mysqli_connect("localhost", "root", "", "database");

    // Check connection
    if($link === false){
        die("ERROR: Could not connect. " . mysqli_connect_error());
    }
     //
    // Attempt insert query execution
    $sql = 'UPDATE wp_users SET user_id = "'.$user_id.'" WHERE user_email = "'.$email.'"';
    if(mysqli_query($link, $sql)){
        return true;
        //echo "Records inserted successfully.";
    } else {
        return false;
        //echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
    }
    // Close connection
    mysqli_close($link);
    } else { 
    $_SESSION['user_id'] = false; } ?>

Looks at database data

When registering the user, an additional id is specified and recorded in the database from the session, the same id I would like to read when logging the user next time, is there any function for that? Or do I have to put a new sql query anyway?

Answers: