Javascript 使用单击“提交”按钮上的复选框更新数据库中所有“我的行”的特定列
因此,当我为所有四行选择“批准”或“拒绝”按钮并单击“提交”按钮时,它会根据所选内容以及我表中的作业名称和所需作业,将我的数据库列状态更新为“批准”或“拒绝”,我是php的新手,请帮助 数据库-->projectdbJavascript 使用单击“提交”按钮上的复选框更新数据库中所有“我的行”的特定列,javascript,php,jquery,mysql,Javascript,Php,Jquery,Mysql,因此,当我为所有四行选择“批准”或“拒绝”按钮并单击“提交”按钮时,它会根据所选内容以及我表中的作业名称和所需作业,将我的数据库列状态更新为“批准”或“拒绝”,我是php的新手,请帮助 数据库-->projectdb no(AI)|jobname|desiredjob|jobexpectations|req1|req2|req3|req4|req5|status. <?php // Approved Rows $countApprove = sizeof($_POST['approve
no(AI)|jobname|desiredjob|jobexpectations|req1|req2|req3|req4|req5|status.
<?php
// Approved Rows
$countApprove = sizeof($_POST['approve']);
for($i=0;$i<$countApprove;$i++)
{
$id = $approve[$i];
mysql_query("UPDATE jobdetails SET status='Approved' WHERE no='$id'");
}
// Denied Rows
$countDeny = sizeof($_POST['deny']);
for($i=0;$i<$countDeny;$i++)
{
$id = $deny[$i];
mysql_query("UPDATE jobdetails SET status='Denied' WHERE no='$id'");
}
?>
表-->作业详细信息
no(AI)|jobname|desiredjob|jobexpectations|req1|req2|req3|req4|req5|status.
<?php
// Approved Rows
$countApprove = sizeof($_POST['approve']);
for($i=0;$i<$countApprove;$i++)
{
$id = $approve[$i];
mysql_query("UPDATE jobdetails SET status='Approved' WHERE no='$id'");
}
// Denied Rows
$countDeny = sizeof($_POST['deny']);
for($i=0;$i<$countDeny;$i++)
{
$id = $deny[$i];
mysql_query("UPDATE jobdetails SET status='Denied' WHERE no='$id'");
}
?>
PHP
<?php
//connect to the server
$link = mysql_connect('localhost', 'guest', 'guest');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//connect to the database
mysql_select_db('projectdb');
//query the database
$query = mysql_query("SELECT * FROM jobdetails WHERE status='In Progress...'");
//fetch the results / convert results into an array
$jobname=array();
$desiredjob=array();
$jobexpectations=array();
$req1=array();
$req2=array();
$req3=array();
$req4=array();
$req5=array();
WHILE($rows = mysql_fetch_assoc($query)){
$jobname[] = $rows['jobname'];
$desiredjob[] = $rows['desiredjob'];
$jobexpectations[] = $rows['jobexpectations'];
$req1[] = $rows['req1'];
$req2[] = $rows['req2'];
$req3[] = $rows['req3'];
$req4[] = $rows['req4'];
$req5[] = $rows['req5'];
}
?>
<form method="post" action="">
<tr id="1">
<td class="type-info" style="width:10%"><?=$jobname[0]?><a class="anchorjs-link" href="#h3.-bootstrap-heading"><span class="anchorjs-icon"></span></a></td>
<td class="type-info" style="width:10%"><?=$desiredjob[0]?><br></br></td>
<td class="type-info" style="width:35%"><?=$jobexpectations[0]?><br></br></td>
<td class="type-info" style="width:35%"><ul><li><?=$req1[0]?></li><li><?=$req2[0]?></li><li><?=$req3[0]?></li><li><?=$req4[0]?></li><li><?=$req5[0]?></li></ul><br></br></td>
<td class="type-info" style="width:5%"><input type="checkbox" value="Approved" id="status"> Approve</label></div><br></br></td>
<td class="type-info" style="width:5%"><input type="checkbox" value="Denied" id = "status"> Deny</label></div><br></br></td>
</tr>
<tr id ="2">
<td class="type-info" style="width:10%"><?=$jobname[1]?><a class="anchorjs-link" href="#h3.-bootstrap-heading"><span class="anchorjs-icon"></span></a></td>
<td class="type-info" style="width:10%"><?=$desiredjob[1]?><br></br></td>
<td class="type-info" style="width:35%"><?=$jobexpectations[1]?><br></br></td>
<td class="type-info" style="width:35%"><ul><li><?=$req1[1]?></li><li><?=$req2[1]?></li><li><?=$req3[1]?></li><li><?=$req4[1]?></li><li><?=$req5[1]?></li></ul><br></br></td>
<td class="type-info" style="width:5%"><input type="checkbox" value="Approved" name="status" id="status"> Approve</label></div><br></br></td>
<td class="type-info" style="width:5%"><input type="checkbox" value="Denied" name="status" id = "status"> Deny</label></div><br></br></td>
</tr>
<tr id="3">
<td class="type-info" style="width:10%"><?=$jobname[2]?><a class="anchorjs-link" href="#h3.-bootstrap-heading"><span class="anchorjs-icon"></span></a></td>
<td class="type-info" style="width:10%"><?=$desiredjob[2]?><br></br></td>
<td class="type-info" style="width:35%"><?=$jobexpectations[2]?><br></br></td>
<td class="type-info" style="width:35%"><ul><li><?=$req1[2]?></li><li><?=$req2[2]?></li><li><?=$req3[2]?></li><li><?=$req4[2]?></li><li><?=$req5[2]?></li></ul><br></br></td>
<td class="type-info" style="width:5%"><input type="checkbox" value="Approved" id="status"> Approve</label></div><br></br></td>
<td class="type-info" style="width:5%"><input type="checkbox" value="Denied" id = "status"> Deny</label></div><br></br></td>
</tr>
<tr id="4">
<td class="type-info"><?=$jobname[3]?><a class="anchorjs-link" href="#h3.-bootstrap-heading"><span class="anchorjs-icon"></span></a></td>
<td class="type-info"><?=$desiredjob[3]?><br></br></td>
<td class="type-info"><?=$jobexpectations[3]?><br></br></td>
<td class="type-info"><ul><li><?=$req1[3]?></li><li><?=$req2[3]?></li><li><?=$req3[3]?></li><li><?=$req4[3]?></li><li><?=$req5[3]?></li></ul><br></br></td>
<td class="type-info" style="width:5%"><input type="checkbox" value="Approved" id="status"> Approve</label></div><br></br></td>
<td class="type-info" style="width:5%"><input type="checkbox" value="Denied" id = "status"> Deny</label></div><br></br></td>
<td class="type-info" style="width:5%"><button type="submit" name="submit" class="styled-button-2" onClick="myFunction()" value="submit">Confirm</button></td>
</td>
</tr>
</body>
</table>
确保为一个特定行选中一个复选框
[注意:您的脚本有遭受SQL注入攻击的风险。请使用mysqli.*
或PDO
]
<?php
//connect to the server
$link = mysql_connect('localhost', 'guest', 'guest');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//connect to the database
mysql_select_db('projectdb');
?>
<form method="post" action="somePage.php">
<table>
<?php
$query = mysql_query("SELECT * FROM jobdetails WHERE status='In Progress...'");
while($rows = mysql_fetch_assoc($query))
{?>
<tr id="<?=$rows['no']?>">
<td class="type-info" style="width:10%">
<?=$rows['jobname']?>
<a class="anchorjs-link" href="#h3.-bootstrap-heading">
<span class="anchorjs-icon"></span>
</a>
</td>
<td class="type-info" style="width:10%"><?=$rows['desiredjob']?><br></br></td>
<td class="type-info" style="width:35%"><?=$rows['jobexpectations']?><br></br></td>
<td class="type-info" style="width:35%">
<ul>
<li><?=$req1['req1']?></li>
<li><?=$req2['req2']?></li>
<li><?=$req3['req3']?></li>
<li><?=$req4['req4']?></li>
<li><?=$req5['req5']?></li>
</ul>
<br></br>
</td>
<td class="type-info" style="width:5%">
<input type="checkbox" name="approve[]" value="<?=$rows['no']?>"><label> Approve</label><br></br>
</td>
<td class="type-info" style="width:5%">
<input type="checkbox" name="deny[]" value="<?=$rows['no']?>"><label> Deny</label>
<br></br>
</td>
</tr>
<?php }?>
</table>
</form>
</body>
问题是不明确的,如果您为特定行同时选中已批准
和已拒绝
复选框,该怎么办?问题不清楚,只有一个应该被选中,请帮助我,我是stuckHey@Aadityan:你们并没有回复。