I am trying to insert some values inside the wp database from the form but it's not getting inserted. your help would be appreciated very much.
我试图从表单中插入一些值在wp数据库中,但它没有插入。非常感谢你的帮助。
<form method="post" action="">
Name: <input type="text" name="name" id="name" />
Email: <input type="text" name="email" id="email"/>
<input type="submit" name="submit"/>
</form>
<?php
global $wpdb;
$name = $_POST['name'];
$email = $_POST['email'];
$table_name = $wpdb->prefix . "user2";
$wpdb->insert( $table_name, array(
'name' => $name,
'email' => $email ) ); ?>
1 个解决方案
#1
0
You can insert using this code :
您可以使用以下代码插入:
<form method="post" action="">
Name: <input type="text" name="name" id="name" />
Email: <input type="text" name="email" id="email"/>
<input type="submit" name="submit"/>
</form>
<?php
if(isset($_POST['submit'])){
global $wpdb;
$name = $_POST['name'];
$email = $_POST['email'];
if(isset($_POST['name ']) && isset($_POST['email '])) {
$table_name = $wpdb->prefix . "user2";
$wpdb->insert( $table_name, array(
'name' => $name,
'email' => $email ) );
}
else{
echo "No parameter";exit;
}
} ?>
OR You can try core php
或者您可以尝试核心PHP
<form method="post" action="">
Name: <input type="text" name="name" id="name" />
Email: <input type="text" name="email" id="email"/>
<input type="submit" name="submit"/>
</form>
<?php
if(isset($_POST['submit'])){
global $wpdb;
$name = $_POST['name'];
$email = $_POST['email'];
$table_name = $wpdb->prefix . "user2";
$sql="insert into '$table_name' table (name,email)values('$name','$email')";
mysql_query($sql);
} ?>
#1
0
You can insert using this code :
您可以使用以下代码插入:
<form method="post" action="">
Name: <input type="text" name="name" id="name" />
Email: <input type="text" name="email" id="email"/>
<input type="submit" name="submit"/>
</form>
<?php
if(isset($_POST['submit'])){
global $wpdb;
$name = $_POST['name'];
$email = $_POST['email'];
if(isset($_POST['name ']) && isset($_POST['email '])) {
$table_name = $wpdb->prefix . "user2";
$wpdb->insert( $table_name, array(
'name' => $name,
'email' => $email ) );
}
else{
echo "No parameter";exit;
}
} ?>
OR You can try core php
或者您可以尝试核心PHP
<form method="post" action="">
Name: <input type="text" name="name" id="name" />
Email: <input type="text" name="email" id="email"/>
<input type="submit" name="submit"/>
</form>
<?php
if(isset($_POST['submit'])){
global $wpdb;
$name = $_POST['name'];
$email = $_POST['email'];
$table_name = $wpdb->prefix . "user2";
$sql="insert into '$table_name' table (name,email)values('$name','$email')";
mysql_query($sql);
} ?>