- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
首先非常感谢大家对这个伟大的网站。
我在大学的最后一年,正在为我的学校开发一个网站。这个问题我有一段时间了,我无法解决它,如果你能帮助我,我将不胜感激,
首先,当管理员登录并转到 Delete.php 时,点击(他/她)将有一个下拉列表来选择要转到的页面,然后单击提交按钮以显示该页面中的所有数据,并且有一个复选框选择列出的所有工作旁边的,这样他们就可以选择要删除的任何工作,然后单击删除按钮以删除指定的工作。
我的代码一直有效,直到用户从许多表中选择并显示所有数据,但它不会删除..
一共有三个函数,SelectOption()
, DisplayOption()
, DeleteOption()
,具体问题是如何添加选择要删除查询的表..
因为如果你输入一个表名并从下拉列表中选择它,它就可以工作..但我希望它是用户可选的。
这是我的代码:
<?php
include('../CIEcon.php');
$GLOBALS['$table']="";
function DisplayOption(){
include('../CIEcon.php');
echo '
<form action= "Delete.php" method = "post">
<table width ="40%" cellpadding ="4" border="1" align="center" >
<tr >
<th style ="color: white; background-color: #f26822 ; " > Select a Catagory To Delete From </th>
</tr>';
echo "<tr>
<td>".
"<select name = lists >
<option name= nothing value= 0 selected >Choose a Catagory</option>
<option name= nothing value= 1> Advertising </option>
<option name= nothing value= 2> Fiscal </option>
<option name= nothing value= 3> Food </option>
<option name= nothing value= 4> Shopping </option>
<option name= nothing value= 5> Rentals </option>
<option name= nothing value= 6> Setting up </option>
<option name= nothing value= 7> Performances </option>
<option name= nothing value= 8> Registration/Ushering </option>
<option name= nothing value= 9> Master of Ceremonies </option>
<option name= nothing value= 10> Cleaning up </option>
<option name= nothing value= 11> Others </option>
</select>"
." </td>
</tr>";
echo '
</table>
<br/>
<div align="center">
<input type="submit" name="submit" value="submit" />
<input type="reset" value="Clear" />
<hr> <hr>
</div>
</form>
';
///
};
function SelectOption(){
include('../CIEcon.php');
///
if(isset($_POST['submit'])){
if(isset($_POST['submit'])) // second submit
{
$errorMessage = "";
if(($_POST['lists'])== 0) // trying to get error if user don't choose.
{
$errorMessage .= "<li>You Forgot to Choose !</li>";
}
$lists = $_POST['lists']; // <-save info in variable based on user input
if(!empty($errorMessage))
{
echo("<p>There was an error with your form:</p>\n");
echo("<ul>" . $errorMessage . "</ul>\n");
die();
}
} // end of second submit
switch($lists)
{
case '1':
$GLOBALS['$table'] ="Advertising";
break;
case '2':
$GLOBALS['$table'] ="Fiscal";
break;
case '3':
$GLOBALS['$table']="Food";
break;
case '4':
$GLOBALS['$table'] ="Shopping";
break;
case '5':
$GLOBALS['$table'] ="Rentals";
break;
case '6':
$GLOBALS['$table'] ="SettingUp";
break;
case '7':
$GLOBALS['$table'] ="Performances";
break;
case '8':
$GLOBALS['$table'] ="Registration";
break;
case '9':
$GLOBALS['$table'] ="MasterOfCeremonies";
break;
case '10':
$GLOBALS['$table'] ="Cleaning";
break;
case '11':
$GLOBALS['$table']="Others";
break;
default;
echo 'Unsupported category';
break;
}
if ($GLOBALS['$table'] != ""){
$sql = "SELECT * FROM ". $GLOBALS['$table']. " ";
$result = mysqli_query($dbCIE, $sql) or die(mysqli_error($dbCIE));
/// NOW DISPLAY ALL INFO FROM CHOSEN DATABASE...///
echo "
<form action= 'Delete.php' method = 'post'>
<table cellpadding ='4' border='1' width='80%' align='center'>
<tr>
<th>Check </th>
<th>Job's Name</th>
<th>Description</th>
<th> No Students needed</th>
<th>Due Date</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<br>";
echo "<tr>";
echo "<td> <input type='checkbox' name='Id[]' value='". $row['Id'] ."' /> </td>";
echo "<td>" . $row['JobName'] . "</td>";
echo "<td>" . $row['Description'] . "</td>";
echo "<td>" . $row['NoStudent'] . "</td>";
echo "<td>" . $row['DueDate'] . "</td>";
echo "</tr>";
}
echo "</table>";
/// END THE SEARCH HERE...........///
echo " <br>
<div align='center'>
<input type='reset' value='clear' >
<input type='submit' name='delete' value='delete'>
</div>
</form>";
} // End if !table="";
mysqli_close($dbCIE);
//
} else { }
///
};// end of function SelectOption
function DeleteOption(){
include('../CIEcon.php');
$tbl = $GLOBALS['$table'] ;
echo $tbl ." beggning of function" ;
if(isset($_POST['delete'])) {
if( empty($_POST['Id']) || $_POST['Id'] == 0 ){
echo"<h4> please choose something to delete </h4>";
}else{
echo "test 1: pass ";
$impid = implode("' , '" , $_POST['Id']);
echo $GLOBALS['$table']."before SQL QUERY" ;
$sqlDelete = "DELETE FROM ". $GLOBALS['$table']. " WHERE Id IN ('" . $impid . "')";
$DeleteQuery = mysqli_query($dbCIE,$sqlDelete) or die ("Error : ".mysqli_error($dbCIE));
}
}// end of delete...
}; // End of Delete Function..
function CloseDB(){};
?>
</style>
<head><title> ..DeleteFFF.. </title></head>
DeleteFFF.php
<body>
<!-- <a href= "../AdminIndex.php" > <button> Main Page </button></a> -->
</body>
</html>
最佳答案
与其在 DELETE 查询中使用全局变量(在执行删除 POST 时可能未设置),不如在单击删除时将表名与 POST 一起传递。
您已经在使用 $_POST['Id']
你从echo "<td> <input type='checkbox' name='Id[]' value='". $row['Id'] ."' /> </td>";
得到的
你可以对表名做同样的事情:
echo "<td> <input type='checkbox' name='Table[]' value='". $GLOBALS['$table'] ."' /> </td>";
然后您可以在 $_POST['Table']
的删除查询中使用它.
理想情况下,您应该去掉所有地方的全局变量(它们通常是个坏主意),但这是最快的解决方案。
关于php - 删除查询不起作用 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34978846/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!