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

I turned WP posts into web forms, which write user data into the database.Now,I want to insertthe username of logged

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();




?>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745628753a4636972.html

相关推荐

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

    I turned WP posts into web forms, which write user data into the database.Now,I want to insertthe username of logged

    22天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信