0
我在用javascript打開的php中彈出一個窗體。我想要這個被髮送到我的數據庫,當我點擊提交。 PHP表單工作正常,沒有JavaScript,但添加它時不起作用。你有任何想法如何解決這個問題。用javascript提交一個php彈出窗體
</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'])); }
究竟什麼不行?任何錯誤消息? –
您是否檢查了螢火蟲控制檯的js錯誤? – jchapa
通過HTML驗證程序對其進行修改。你的表單中有一個未打開的關閉p標籤。瀏覽器可能會錯誤地渲染表單。嘗試修復它,也許你會更接近你的目標。很高興看到你的PHP工作 – danronmoon