awesome people of the Stack Community!
Like the newbie coder I am, it took many hours but at last I got:
- a HTML form inside wordpress ->
- to submit value to MySQL database ->
- and then store the values inside the table.
This page and form requires a login to use, so what I'm trying to do now is getting the wp_current_user_id stored in a field in the table "order" and the field userID.
Does anyone know if this is possible?
Thanks in advance for any kinds of help. Cheers.
order_confirmation.php
<?php
$db_name = "dbname";
$db_user = "username";
$db_pass = "cool_password";
$db_host = "hostname";
include 'config.php';
$db_conn = connectToDB($db_host, $db_user, $db_pass, $db_name);
//Get values from the form then -> database
$sql = mysqli_query($db_conn, "
INSERT INTO ordre(
user_fname,
user_lname,
user_address,
user_email,
user_phone,
service_chosen,
user_note,
order_date,
statusID
)
VALUES(
'".$_POST['user_fname']."',
'".$_POST['user_lname']."',
'".$_POST['user_address']."',
'".$_POST['user_email']."',
'".$_POST['user_phone']."',
'".$_POST['service_chosen']."',
'".$_POST['user_note']."',
'".date('Y-m-d')."',
'1'
)
");
if($sql == TRUE) {
echo "<p>Yay it worked</p>";
);
} else {
echo "<p>Error: " . mysqli_errno($sql) . "</p>";
}
?>
config.php
<?php
function connectToDB($db_host, $db_user, $db_pass, $db_name) {
//Create the db connection
$db_conn = new mysqli($db_host, $db_user, $db_pass, $db_name);
//Print out an error if any
if($db_conn->connect_error) {
die('Error #' . $db_conn->connect_errno . ': ' . $db_conn->connect_error);
}
else {
//Connected msg
echo "Connected: " . $db_conn->host_info;
}
return $db_conn;
}
?>

require('wp-blog-header.php')which is in the root, then usewp_get_current_user()->IDto get the user ID if logged in.. Also look at$wpdbcodex.wordpress.org/Class_Reference/wpdb for handling db queries..wp_current_user_idstored in a table. Is it okay to use$wpdbthis time?require ('../wp-blog-header.php'); global $wpdb; global $current_user; get_currentuserinfo(); $skrivID = $current_user->ID;Then in the insert query I added userID on the top and used the variable under VALUES. I'll update the thread. Thanks again!