Insert data in database using form
-
Hello WordPress admin,
I have created the form and insert data into database, after submit the “alert box” it says unable to save. this is my code in function.php
if (isset($_POST['submitbtn'])) { $data = array( 'title' => $_POST['title'], 'author' => $_POST['author'], ); $table_name ='mybook'; $result = $wpdb->insert($table_name, $data, $format=null); if ($result==1) { echo "<script>alert('Book Saved');</script>"; }else{ echo "<script>alert('Unable to Save');</script>"; } } and this my code to my frontpage.php <form method="post" > <div class="form-group"> <input id="title" type="text" name="title" placeholder="Book Title" class="form-group input-sm"> </div> <div class="form-group"> <input id="author" type="text" name="author" placeholder="author" class="form-group input-sm"> </div> <div class="row justify-content-center"> <div class="col-xs-4 col-sm-4 col-md-4"> <input type="submit" value="Submit" class="btn btn-info btn-block" name="submitbtn"> </div> </div> </form>
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
The topic ‘Insert data in database using form’ is closed to new replies.