Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP编辑SQL中的特定行_Php_Html_Mysql_Database - Fatal编程技术网

如何使用PHP编辑SQL中的特定行

如何使用PHP编辑SQL中的特定行,php,html,mysql,database,Php,Html,Mysql,Database,我对PHP和SQL相当陌生。 我希望能够将任务分配给某个用户,并使用分配给该任务的用户名更新数据库中的该行。 这是我的密码: <table border="0" width="1100px" style= "font-size: 12px" > <thead> <tr valign="top" align="left"> <th height="20"></th> <th height="20"&g

我对PHP和SQL相当陌生。 我希望能够将任务分配给某个用户,并使用分配给该任务的用户名更新数据库中的该行。 这是我的密码:

<table border="0" width="1100px" style= "font-size: 12px" >
  <thead>
    <tr valign="top" align="left">
    <th height="20"></th>
      <th height="20">Customer</th>
      <th>Vehicle</th>
      <th>Appt Time</th>
      <th>Notes</th>
      <th>Assign</th>
      <th>Action</th>
      <tr><td valign="top" colspan="6"><hr><br></td></tr>
    </tr>
  </thead>
  <tbody>
    <?php
      while( $row = mysql_fetch_assoc( $result ) ){
        echo
        "<tr valign='center'>

          <td width='50'><b>{$row['id']}</td>

            <td width='220' height='70'><b>{$row['firstname']}
          </td>


          <td width='240'><b>{$row['car']}</b> <br>{$row['reg']}</td>
          <td width='170'>Monday<br>24 September<br>17:00</td>

          <td width='240'>{$row['notes']}<br><b>Status:</td>
          <td width='240'>
          <form action='bookings.php' method='post'>
          <select style='width:90px' class='reg' name='assign'required>
          <option value=''></option>
          <option value='User1'>User1</option>
          <option value='User2'>User2</option>
          <option value='User3'>User3</option>
          <option value='User4'>User4</option>
          <option value='User5'>User5</option>
         </select><input type='submit' value='>'  class='assignButton'/></form>
          </td><td>
          <button class='myButton'>Edit</button>
          </td>
          <tr><td colspan='6'><hr class='hrTitle'></td></tr>
        </tr>\n";
      }  
    ?>

  </tbody>
</table>

顾客
车辆
应用时间
笔记
分配
行动



尝试以下步骤

  • 为“提交”按钮指定名称

    <input type='submit' value='>' name='submit' class='assignButton'>
    

  • 希望有帮助。

    updatetable\u name SET value1=$your\u value,value2=$your\u value2其中user\u id=$user\u id
    very ruff猜测:
    UPDATE。。。set assigned=1,其中user=$\u POST['assign']
    @nogad-恶心,它需要转义!我说你使用的数据库功能是不安全的、未维护的,而且在将近10年的时间里都不推荐使用。住手。非常感谢,你说的我都做了,但几乎什么也没发生。没有错误,但该行未分配给任何人。知道为什么会这样吗?给我看看你的代码。bookings.php文件和包含表单的html。
    <input type="hidden" name="id" value='$row["id"]''>
    
    if(isset($_POST["submit"])){ //checks if the form was submitted
        $id = $_POST["id"]; //id of the customer
        $assign = $_POST["assign"]; //your selected value
        $query = "UPDATE table SET columnToModify = '$assign' WHERE id = '$id'";
        $result = $connection->query($query); //run the query
    }