我在填充数据库表的页面上有一个表单:
<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>
这里是输入。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;
?>
我正在尝试将用户名作为“id”传递给数据库。我收到下一个错误:
Fatal error: Call to undefined function wp_get_current_user() in /home/xxx/input.php on line 10
我试图改变现状,但仍然没有奏效。。