wpdb->insert() inserts two rows into the table instead of one


I have the following code to insert a row to my members table.

global $wpdb;
if ( isset( $_POST['submit'] ) ){
 $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" />

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.

Asmat Ali 8 months 2020-12-10T00:10:23-05:00 0 Answers 7 views 0

Leave an answer