【发布时间】:2017-03-08 20:06:39
【问题描述】:
我对 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>
如您所见,我有许多可供选择的用户,我希望能够将该任务分配给选择列表中的用户。 非常感谢任何帮助。
【问题讨论】:
-
UPDATE table_name SET value1 = $your_value, value2 = $your_value2 WHERE user_id = $user_id -
非常粗鲁的猜测:
UPDATE ... set assigned=1 where user=$_POST['assign'] -
@nogad yuck,它需要被转义!
-
我说这很糟糕
-
您正在使用不安全、未维护且已弃用近 10 年的数据库功能。停下来。 stackoverflow.com/q/12859942/1255289