最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

database - Can someoene please help with customization of a post?

matteradmin5PV0评论

I turned WP posts into web forms, which write user data into the database.

Now, I want to insert the username of logged in user into the database - automatically.

I attempted $current_user = wp_get_current_user();

However, this doesn't work.

Can someone please look at the code ?

<?php
// Preuzmi podatke iz HTML formulara i stavi ih u varijable

$transactionname = $_POST['transactionname'];
$transactionamount = $_POST['transactionamount']; 
$recurrence = $_POST['recurrence']; 
$datedue   = $_POST['datedue'];
$reasonforproposing = $_POST['reasonforproposing'];  
 $current_user = wp_get_current_user();



// Konektuj se na bazu 

$servername = "";
$username = "";
$password = "";
$dbname = "";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "INSERT INTO prijedlozibudzeta (transactionname,transactionamount,recurrence, datedue, reasonforproposing,user)
VALUES ('$transactionname','$transactionamount', '$recurrence ', '$datedue ','$reasonforproposing','$current_user')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();




?>
Post a comment

comment list (0)

  1. No comments so far