我在 php 中有一个由 javascript 打开的弹出表单。我希望在单击提交时将其发送到我的数据库。php 表单在没有 javascript 的情况下可以正常工作,但是在添加时它不起作用。你知道如何解决这个问题吗?
</style>
<script type='text/javascript'>
$(document).ready(function() {
$('#box_form').dialog({
autoOpen: false,
height: 375,
width: 350,
modal: true,
buttons: [
{
text: "Cancel",
click: function() {
$(this).dialog("close");
}},
{
text: "Submit",
click: function() {
$('#former').submit();
}}
]
});
$('#clicky').button().click(function(e){
$('#box_form').dialog('open');
});
});
</script>
</head>
<body>
<form id="former" method="post" action="film_post.php" name="former">
<div id="box_form">
<select id="option" name="option">
<option value="film">film</option>
<option value="livre">livre</option>
<option value="musique">musique</option>
</select></p>
<p>
<select id="star" name="star">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select></p>
<label for="nom">nom</label> : <input type="text" name="nom" id="nom" /><br />
</div>
</form>
<input type="button" id="clicky" value="Show Form">
而film_post.php 文件是:
try
{
$bdd = new PDO('mysql:host=localhost;dbname=website', 'root', 'root');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$option = $_POST['option'];
$star = $_POST['star'];
if ($option == film AND $star = 1) {
$req = $bdd->prepare('INSERT INTO film (film, star) VALUES(?,?)');
$req->execute(array($_POST['nom'],$_POST['star'] )); }
elseif ($option == film AND $star = 2) {
$req = $bdd->prepare('INSERT INTO film (film, star) VALUES(?,?)');
$req->execute(array($_POST['nom'],$_POST['star'] )); }
elseif ($option == film AND $star = 3) {
req = $bdd->prepare('INSERT INTO film (film, star) VALUES(?,?)');
$req->execute(array($_POST['nom'],$_POST['star'] )); }