如何將php代碼置於javascript代碼中,以便在用戶單擊確定框上的確定後,它將值插入數據庫中? (形式提交給自己,但我沒有帶提供表單代碼)如何在確認框上單擊確定後插入值
下面是整個代碼:
<?php
session_start();
$username="xxx";
$password="xxx";
$database="xxx";
mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die("Unable to select database");
$sql = "INSERT INTO Media (Image, Video, Audio)
VALUES (' ". mysql_real_escape_string($image) . "',
' ". mysql_real_escape_string($video) . "',' ". mysql_real_escape_string($audio) . "')";
mysql_query($sql);
mysql_close();
?>
<script>
function insertQuestion(form) {
var $tbody = $('#qandatbl > tbody');
var $tr = $("<tr class='optionAndAnswer' align='center'></tr>");
var $image = $("<td class='image'></td>");
var $video = $("<td class='video'></td>");
var $audio = $("<td class='audio'></td>");
$tr.append($image);
$tr.append($video);
$tr.append($audio);
$tbody.append($tr);
}
function showConfirm(){
var confirmMsg=confirm("Make sure that your details are correct, once you proceed after this stage you would not be able to go back and change any details towards Questions, Options and Answers for your Session." + "\n" + "\n" + "Are you sure you want to Proceed?" + "\n");
if (confirmMsg==true)
{
submitform();
}
}
function submitform()
{
var QandAO = document.getElementById("QandA");
QandAO.submit();
}
</script>
<body>
<form id="QandA" action="<?php echo htmlentities($action); ?>" method="post" >
<table id="qandatbl" align="center">
<thead>
<tr>
<th class="image">Image</th>
<th class="video">Video</th>
<th class="audio">Audio</th>
</tr>
</thead>
<tbody></tbody>
</table>
<p><input id="submitBtn" name="submitDetails" type="submit" value="Submit Details" onClick="myClickHandler(); return false;" /></p>
</form>
<script type="text/javascript">
function myClickHandler(){
if(validation()){
showConfirm();
}
}
</script>
</body>
下$操作方法是在表單會根據是否有匹配與否之間$ sessionMinus和$ _SESSION ['initial_count']。如果有匹配,發佈到create_session2.php,否則將表單發佈到自身。
if ($sessionMinus == $_SESSION['initial_count']){
$action = 'create_session2.php';
}else if($sessionMinus != $_SESSION['initial_count']){
$action = $_SERVER['PHP_SELF'];
}
你可以通過AJAX提交表單,並有表單處理頁面返回的輸出,以判斷它成功與否? – 2012-03-31 21:37:48
'var confirmMsg = confirm(你確定要繼續嗎?「+」\ n「);'不用開始'''在'Are [..]'之前'... – 2012-03-31 21:40:05
@GabrielSantos,是的,這是一個錯字我在問題中鍵入它,它確實以「在我的應用程序中開始」 – user1304197 2012-03-31 21:41:05