user5358888 user5358888 - 1 year ago 178
PHP Question

Insert data from HTMl field and bootstrap popup window

I have an html form with one text field and one bootstrap module popup and two types of submit.

Iam able to collect the value from the html field using $_POST but in that am not getting the value from the popup window.


<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
<script src=""></script>
<script src=""></script>
<form id="contactform" method="post" action="http://****/post.php">
<label for="name">Name :</label>
<input type="text" name="name">
<button type="submit"> Submit</button>
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Update</button>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<div class="modal-body">
<label for="plan">Plan :</label>
<input type="radio" name="plan" value="Yes" > Yes</input>
<input type="radio" name="plan" value="No"> No</input>
<div class="modal-footer">
<button type="submit" formaction="update.php" class="btn btn-default" data-dismiss="modal">Submit</button>

Here for two submits am using two php files...1)post.php and 2)update.php
Where one submit is outside(post.php) the popup and other inside(update.php) the popup.
In post.php i am only collecting text field using

$name = $_POST['name'];

Which is working,But update.php code :

$conn = mysqli_connect("localhost", "username", "password", "database");
if($conn === false){
die("ERROR: Could not connect. " . mysqli_connect_error($conn));
$name = $_POST['name'];
$plan = $_POST['plan'];
$sql = "INSERT INTO table (name, plan) VALUES ('$name', '$plan')";
if(mysqli_query($conn, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);

Here in db am only able to collect name but plan value am not able to collect.

Please help to collect the values form both html field and popup window field.

Thanks in advance.


For your button in popup remove data-dismiss like this:

<button type="submit" formaction="update.php" class="btn btn-default">Submit</button>

Then in your post.php process just $name and in update.php $plan and $post.