使用带有PHP代码的下拉列表将数据插入phpmyadmin

时间:2019-03-05 19:40:57

标签: php

我正在尝试从下拉列表中插入一些数据,但是没有插入。

我正在尝试从获取while( $row = mysqli_fetch_array($result,MYSQLI_ASSOC)){的While循环中的PHP代码中插入它。

我尝试使用isset($_POST[''])? $_POST['']:'';,但效果不佳

 <?php $sql="SELECT * from cs_windows_mac where type='windows'";    
 $result = mysqli_query($dbhandle,$sql);
 while( $row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
 print ("<tr>");
  print(" <td>".$row['id']."</td>");  
  print(" <td>".$row['mac_address']."</td>"); 
  print(" <td>".$row['type']."</td>"); 
 if ($row['ip']=='' and $row['internet_conn']=='' and $row['office']=='' and $row['eclipse']=='' and $row['bluej']=='' and $row['os']==''
 and $row['assign_f']=='' and $row['requested_F']=='' and  $row['male']==''){

     print("<td><select name='ip' id='ip'>
        <option value=''>Select One</option>
        <option value = 'Fixed'>Fixed</option>
        <option value = 'Changed'>Changed</option>
</select></td>");
 print("<td><select name='internet' id='internet'>
        <option value=''>Select One</option>
        <option value = 'Connected'>Connected</option>
        <option value = 'Broken Cable'>Broken Cable</option>
        <option value = 'Broken Port'>Broken port</option>
</select></td>");
 print("<td><select name='moffice' id='moffice'>
        <option value=''>Select One</option>
        <option value = 'Activated'>Activated</option>
        <option value = 'Not Activated'>Not Activated</option>
        <option value = 'Not Installed'>Not Installed</option>
</select></td>");
 print("<td><select name='eclipse' id='eclipse'>
        <option value=''>Select One</option>
        <option value = 'Installed'>Installed</option>
        <option value = 'Not Installed'>Not Installed</option>
</select></td>");
 print("<td><select name='blue' id='blue'>
        <option value=''>Select One</option>
        <option value = 'Installed'>Installed</option>
        <option value = 'Not Installed'>Not Installed</option>
</select></td>");
 print("<td><select name='os' id='os'>
        <option value=''>Select One</option>
        <option value = 'Activated'>Activated</option>
        <option value = 'Not Activated'>Not Activated</option>
</select></td>");
 print("<td><select name='Assign_F' id='Assign_F'>
        <option value=''>Select One</option>
        <option value = 'Sarah'>Sarah</option>
        <option value = 'Zahra'>Zahra</option>
</select></td>");
echo "<td><a href='CS labs Windows Req.php?id=".$row['id']."'>Fix Please</a></td>";
print("</tr>");
 }

这是插入部分:

$id = $_GET['id'];
$ip = $_POST['ip'];
$internet= $_POST['internet'];
$moffice=$_POST['moffice'];
$eclipse=$_POST['eclipse'];
$blue=$_POST['blue'];
$os=$_POST['os'];
$assign_F=$_POST['Assign_F'];

$query= "INSERT INTO cs_windows_mac  (`ip`, `internet_conn`, `office`, 
`eclipse`, `bluej`, `os`, `assign_f`)

 VALUES('$ip','$internet','$moffice','$eclipse','$blue','$os','$assign_F')  
 WHERE id ='$id'";
 if (mysqli_query($dbhandle,$query)) {
   mysqli_close($dbhandle);
    header('Location:cs labs.php'); 
   exit;
  } else {
  echo "Error inserting record";}

有人可以告诉我问题是什么以及如何解决。

1 个答案:

答案 0 :(得分:1)

您尝试插入8列,但仅提供了7个值...