user5358888 user5358888 - 6 months ago 118
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.

HTML :

<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<form id="contactform" method="post" action="http://****/post.php">
<tr>
<td>
<label for="name">Name :</label>
</td>
<td>
<input type="text" name="name">
</td>
</tr>
<tr>
<td>
<button type="submit"> Submit</button>
&nbsp;
<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>
<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>
<div class="modal-footer">
<button type="submit" formaction="update.php" class="btn btn-default" data-dismiss="modal">Submit</button>
</div>
</div>
</div>
</div>
</td>
</tr>
</form>
</body>
</html>


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 :

<?php
$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.

Answer

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.