Php 批准表格提交
我在创建审批表时遇到了麻烦,因为我还是php初学者 这个想法是 用户提交表单am,在表中已批准的行中设置默认值“0” 因此,管理员会在后台显示此表中的所有成员,其中approved=“0” 这就是代码Php 批准表格提交,php,mysql,Php,Mysql,我在创建审批表时遇到了麻烦,因为我还是php初学者 这个想法是 用户提交表单am,在表中已批准的行中设置默认值“0” 因此,管理员会在后台显示此表中的所有成员,其中approved=“0” 这就是代码 <code> <?php $con = mysql_connect("localhost","ebarea_epic","..."); if (!$con) { die('Could not connect: ' . mysql_error());
<code>
<?php
$con = mysql_connect("localhost","ebarea_epic","...");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("ebarea_epic", $con);
$query = "select * from medicalrep where approved='0'";
$result=mysql_query($query);
echo "<table border='1'>
<tr>
<th>User Name</th>
<th>Password</th>
<th>Mobile </th>
<th>Address</th>
<th>Faculty</th>
<th>Graduation Year</th>
<th>Region</th>
<th>Area</th>
<th>Line</th>
<th>Appointment Date</th>
<th>Resign Data</th>
<th>Job Title</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['password'] . "</td>";
echo "<td>" . $row['Mobile'] . "</td>";
echo "<td>" . $row['Address'] . "</td>";
echo "<td>" . $row['Faculty'] . "</td>";
echo "<td>" . $row['Graduation Year'] . "</td>";
echo "<td>" . $row['Region'] . "</td>";
echo "<td>" . $row['Line'] . "</td>";
echo "<td>" . $row['Area'] . "</td>";
echo "<td>" . $row['Appointment'] . "</td>";
echo "<td>" . $row['Resign'] . "</td>";
echo "<td>" . $row['job_title'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
</code>
我只想为每个表用户添加复选框,当选中时,他们的状态在approved列中更改为1 谢谢大家
$con = mysql_connect("localhost","ebarea_epic","...");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("ebarea_epic", $con);
$query = "select * from medicalrep where approved='0'";
$result=mysql_query($query);
$i = 1; //counter for the checkboxes so that each has a unique name
echo "<form action='process.php' method='post'>"; //form started here
echo "<table border='1'>
<tr>
<th>User Name</th>
<th>Password</th>
<th>Mobile </th>
<th>Address</th>
<th>Faculty</th>
<th>Graduation Year</th>
<th>Region</th>
<th>Area</th>
<th>Line</th>
<th>Appointment Date</th>
<th>Resign Data</th>
<th>Job Title</th>
<th>Update</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['password'] . "</td>";
echo "<td>" . $row['Mobile'] . "</td>";
echo "<td>" . $row['Address'] . "</td>";
echo "<td>" . $row['Faculty'] . "</td>";
echo "<td>" . $row['Graduation Year'] . "</td>";
echo "<td>" . $row['Region'] . "</td>";
echo "<td>" . $row['Line'] . "</td>";
echo "<td>" . $row['Area'] . "</td>";
echo "<td>" . $row['Appointment'] . "</td>";
echo "<td>" . $row['Resign'] . "</td>";
echo "<td>" . $row['job_title'] . "</td>";
echo "<td><input type='checkbox' name='check[$i]' value='".$row['ID']."'/>";
echo "</tr>";
$i++;
}
echo "</table>";
echo "<input type='submit' name='approve' value='approve'/>";
echo "</form>";
mysql_close($con);
虽然您在这里使用的是mysql_*函数,但我建议您使用
编辑:
根据您的要求,这是更新
在管理面板脚本中更改此代码:
echo "<input type='submit' name='approve' value='approve'/>";
注意
您可能不希望选中多个复选框进行编辑。您只需要稍微调整上面的javascript代码,它就会在表单提交时将ID作为post变量发送,您可以从中检索一个条目的详细信息,然后编辑函数就会出现。我把它留给你。试试看,在这里发布你的试用代码,如果它不起作用,我会给你一个解决方案。lol,实际问题是什么?我只想为每个表用户添加复选框,当选中时,他们的状态在approved列中变为1,谢谢在数据库中创建一列。默认情况下,将0视为未批准,将1视为已验证。在管理面板中,为每个帖子创建表单。相应地,对于每个选中的条目,将“批准”列更新为1。您还可以使用ajax。你有很多方法可以做到这一点。如果你不能为此编写代码,请告诉我。我会把这些代码作为答案发布。如果你发布这些代码,那就太棒了:)百万谢谢!是的,我在sql中做了一行,默认值为0,但问题在于如何创建表单和更新用户状态:(呜呜呜!!竖起大拇指!!:D您能告诉我是否可以在“批准”旁边添加“编辑”按钮或“删除”按钮来编辑表单或删除表单,以及如何删除表单吗?很抱歉打扰您,但我非常确定您很有天赋和专业……提前谢谢:)
echo "<input type='submit' name='approve' value='approve'/>";
echo "<input class='action' type='button' name='approve' value='approve' />";
echo "<input class='action' type='button' name='edit' value='edit' />";
echo "<input class='action' type='button' name='delete' value='delete' />";
echo "<input type='hidden' name='action' value='' id='action' />"; //Action (edit, approve or delete) will be set here which will be passed as POST variable on form submission
<script type="text/javascript" src="jquery-1.7.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.action').click(function(){
var action = $(this).attr('name');
$('#action').val(action);
$(this).closest('form').submit();
})
})
</script>
if (isset($_POST['approve'])) {
if (isset($_POST['check'])) {
foreach ($_POST['check'] as $value) {
$sql = "UPDATE post SET post_approved = 1 WHERE ID = $value"; //write this query according to your table schema
mysql_query($sql) or die(mysql_error());
}
}
} elseif(isset($_POST['edit'])){
//do the edit things here
} elseif(isset($_POST['delete'])){
foreach ($_POST['check'] as $value){
$sql = "DELETE FROM post WHERE ID=$value";//modify it
mysql_query($sql) or die(mysql_error());
}
}