I have a form on a page that populates the database table:
<table border="1">
<tr>
<td align="center">Form Input Employees Data</td>
</tr>
<tr>
<td>
<table>
<form method="post" action="input.php">
<tr>
<td>Product Name</td>
<td><input type="text" name="name" size="20">
</td>
</tr>
<tr>
<td>Brand</td>
<td><input type="text" name="brand" size="40">
</td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit" name="submit" value="Sent"></td>
</tr>
</table>
</td>
</tr>
</table>
And here is input.php:
<?
//the example of inserting data with variable from HTML form
//input.php
mysql_connect("localhost","xxx","xxx");//database connection
mysql_select_db("xxxxxxx");
$current_user= wp_get_current_user();
$id= $current_user->user_login;
//inserting data order
$order = "INSERT INTO wp_userdata
(id, product_name, product_brand)
VALUES
('$id',
'$_POST[name]',
'$_POST[brand]')";
//declare in the order variable
$result = mysql_query($order); //order executes
if($result){
echo("<br>Input data is succeed");
} else{
echo("<br>Input data is fail");
}
echo $id;
?>
I am trying to pass username to a database as "id". I am getting next error:
Fatal error: Call to undefined function wp_get_current_user() in /home/xxx/input.php on line 10
I tried to change things around but still not working..
input.php
load any of the WordPress functionality?wp_get_current_user()
is a WordPress function, so you need to load up WordPress before you use it. Also, don't use PHP short tags -- use<?php
instead of<?
in your code. And last, check out thewpdb
class, which simplifies interacting with the WordPress DB. – Pat J Aug 8 at 17:46