wpdb->insert() inserts two rows into the table instead of one
Question
I have the following code to insert a row to my members table.
<?php
global $wpdb;
if ( isset( $_POST['submit'] ) ){
$fname=$_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$city = $_POST['city'];
$table = $wpdb->prefix . 'members';
$wpdb->insert($table, array('id' => NULL, 'fname' => $fname, 'lname' => $lname, 'email' => $email, 'city' => $city));
}
?>
<form action="" id="postjob" method="post">
<label>First Name: </label>
<input type="text" name="fname" id="fname" value="" required/>
<label>Last Name: </label>
<input type="text" name="lname" id="lname" value="" required/>
<label>Email: </label>
<input type="text" name="email" id="email" value="" required/>
<label>City: </label>
<input type="text" name="city" id="city" value="" required/>
<input type = "submit" name = "submit" value = "Submit" />
</form>
this runs successfully but inserts two rows at a time instead of one, for example:
1 Asmat Ali xyz@gmail.com Swat
2 $fname $lname $email $city
The same code works fine when I use it on a page on my site but if I use it on an admin page, it generates the unwanted output. Any help would be greatly appreciated.
0
1 month
0 Answers
7 views
0
Leave an answer
You must login or register to add a new answer .