我正在尝试添加一个“确认框”,上面写着“您确定要更新/删除问题吗?”当我点击“更新”和/或“删除”按钮时。
我已经尝试添加
了onclick="return confirm('Are you sure you want to logout?');"
<input type="submit" value="Add Question" onclick="return confirm('Are you sure you want to update/delete question?');">
我提供了两个php文件。可能不需要整个文件,但我希望你能理解我的问题,并尽你所能帮助你。谢谢。
档案:questions_menu.php
<?php
$username = "root";
$password = "";
$hostname = "localhost";
$database = "basketball_database";
$table = "question_bank";
$con = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MYsql");
//echo "Connected to mysql<br>";
mysql_select_db("$database")
or die("Could not select Basketball_database");
//echo "Connected to database";
//update when update button pressed
if(isset($_POST['update'])){
$UpdateQuery = "UPDATE $table SET question_description='$_POST[description]', option_a='$_POST[option1]', option_b='$_POST[option2]', option_c='$_POST[option3]', answer='$_POST[dropdown]', question_id='$_POST[questionID]' WHERE question_id='$_POST[hidden]'";
mysql_query($UpdateQuery, $con);
};//end of if statement
//delete when delete button pressed
if(isset($_POST['delete'])){
$DeleteQuery = "DELETE FROM $table WHERE question_id='$_POST[hidden]'";
mysql_query($DeleteQuery, $con);
};//end of if statement
$mysql = "SELECT * FROM $table";
$mydata = mysql_query($mysql,$con);
//create table
echo "<table border=1
<tr>
<th>Question ID</th>
<th>Question Description</th>
<th>Option 1</th>
<th>Option 2</th>
<th>Option 3</th>
<th>Answer</th>
<th>Picture</th>
<th>Video</th>
</tr>";
//insert data into rows
while($records = mysql_fetch_array($mydata)){
echo "<form action=questions_menu.php method=post>";
echo "<tr>";
echo "<td>"."<input type=text name=questionID size=10 value=".$records['question_id']." </td>";
echo "<td>"."<textarea name=description rows=2 cols=25>".$records['question_description']."</textarea>"."</td>";
echo "<td>"."<input type=text name=option1 size=18 value=".$records['option_a']." </td>";
echo "<td>"."<input type=text name=option2 size=15 value=".$records['option_b']." </td>";
echo "<td>"."<input type=text name=option3 size= 15 value=".$records['option_c']." </td>";
echo "<td>"."<input type=text name=answer size=15 value=".$records['answer']." </td>";
echo "<td>"."<input type=hidden name=hidden value=".$records['question_id']." </td>";
//update button
echo "<td>"."<input type=submit name=update value=Update onclick=return confirm(Are you sure you want to update/delete question?)"." </td>";
//delete button
echo "<td>"."<input type=submit name=delete value=Delete onclick=return confirm(Are you sure you want to update/delete question?)"." </td>";
echo "</tr>";
echo "</form>";//end form
} echo "</table>";
mysql_close();
?> <!-- End of php code-->
答案 0 :(得分:1)
您需要在以下行关闭输入标记:
echo "<td>"."<input type=submit name=update value=Update onclick='return confirm(\"Are you sure you want to update/delete question?\")'>"." </td>";
---------------------------------------------------------------------------------------------------------------------------------------^
您需要在单引号中使用put confirm代码,如上所示。并且还要注意用于消息文本的转义序列。