更新仅检查复选框php的行的sql表

时间:2016-08-25 16:47:24

标签: php sql

我有一个值表,我试图只更新日期。我有一个复选框,我希望只有选中的行在选中时才会更新,用户点击提交按钮。我遇到的问题是让我说我​​有4条记录,我只想更新记录1,2和4。正在发生的事情是记录1,2和3正在更新。我知道它与foreach循环中的数组有关。旁注我知道sql代码允许注入我试图让它首先工作,然后再担心这一点。感谢您提供的所有帮助和时间。

表格代码

$sql = "SELECT * FROM tblUnitMaster WHERE JobNumber = '" . $JobNumber . "' AND `EngReleaseDate` IS NULL OR `EngReleaseDate` = ''  ORDER BY UnitID";
$result=$conn->query($sql);

echo "<style>";
echo "th {";
echo "background-color: #6EB4FF;";
echo "color: white;";
echo "}";
echo "</style>";

echo "<form action=pmReleaseEngineering3.php method=post>";
echo "<input type=hidden name=JobNumber value=$JobNumber />";
echo "<table border=2 cellpadding=4 cellspacing=10>";

echo "<tr>";
echo "<th><b><font size=4></font></b></th>";
echo "<th><b><font size=4>"."Job"."</font></b></th>";
echo "<th><b><font size=4>"."Code"."</font></b></th>";
echo "<th><b><font size=4>"."Model Number"."</font><?b></th>";
echo "<th><b><font size=4>"."Serial Number"."</font><?b></th>";
echo "<th><b><font size=4>"."Scope"."</font></b></th>";
echo "<th><b><font size=4>"."Date"."</font></b></th>";
echo "</tr>";

while ($row=$result->fetch_array())
    {
    echo "<tr>";
    //echo "<td><font color=silver size=4>".$row[0]."</font></td>"; // Unit Number
    echo "<td><input type=checkbox name=check[] value=".$row[0]." checked></td>";
    echo "<td><input name=UnitID type=text font color=silver size=3 value=".$row[0]." readonly/></td>"; // Unit Number
    echo "<td><font color=silver size=4>".$row[5]."</font></td>"; // Job Code
    echo "<td><font color=silver size=4>".$row[2]."</font></td>"; // Model Number
    echo "<td><font color=silver size=4>".$row[3]."</font></td>"; // Serial Number
    echo "<td><font color=silver size=4>".$row[4]."</font></td>"; // Scope
    echo "<td><input name=EngReleaseDate size=6 type=datetime value=" . date('Y-m-d'). " /></td>";      
    echo "</tr>";   
    }
echo "</table>";
echo "<br>";
echo "<button class=button style=vertical-align:middle><span>Submit</span></button>";
echo "</form>";
echo "<br>";

PHP SQL更新TBL代码

include('pmconnect.php');

$JobNumber=$_REQUEST['JobNumber'];    //array
    $UnitID=$_POST['UnitID'];     // array
$EngReleaseDate=$_POST['EngReleaseDate'];      // array 

if(isset($_POST['check'])){
//if(!empty($_POST['check'])) {
foreach($_POST['check'] as $a => $B){

$sql = "UPDATE tblUnitMaster SET " . 
"EngReleaseDate='" . $EngReleaseDate . "'" . 
"WHERE UnitID='" . $UnitID . "'";

//$result=$conn->query($sql); 
if ($conn->multi_query($sql) === TRUE)

echo "<table border=1 cellpadding=4 cellspacing=10>";
     echo "<tbody>";
     echo "<tr>";
        echo "<td><b><font size=4>Unit ID</font></b></td>";
        echo "<td><b><font size=4>Eng. Release</font></b></td>";

     echo "</tr>";

     echo "<tr>";
        echo "<td><font size=4> $UnitID </font></td>";
        echo "<td><font size=4> $EngReleaseDate </font></td>";
     echo "</tr>";
     echo "</tbody>";
  echo "</table>";
  echo"<br>";
}
}

0 个答案:

没有答案