我有学校命令。我需要在他们制作的应用程序上创建删除功能。我目前不知道该如何做。我知道如何在laravel中制作CRUD系统,但这是纯PHP。
ip_list = [{'1403': [-56, -58], 'data': '1'},
{'1403': [-56, -58], 'data': '0'}]
for ip in ip_list:
if ip.get('data') == '1':
ip['mac'] = 'xyz'
print(ip_list)
#[{'1403': [-56, -58], 'data': '1', 'mac': 'xyz'}, {'1403': [-56, -58], 'data': '0'}]
在上面,您可以看到它们执行的 private function add()
{ $klantId = -1;
if (isset($_POST['inputklanten']))
{
$klantId = $_POST['inputklanten'];
}
$row = $this->getKlantVars($klantId);
$rowreservering = $this->getReserveringVars(-1);
$row = array_merge($row, $rowreservering);
$output = "
<form action='?action=add' method='post' enctype='multipart/form-data'>
<label>Selecteer klant
</label>
<select id='inputklanten' name='inputklanten'>" .
$this->getKlanten() . "
</select>
<input type='submit' name='submit_klantselecteren'
id='submit_klantselecteren' value='Selecteer klant'/>
</form>" .
$this->showReserveringForm($row);
return $output;
}
protected function edit()
{
$reserveringId = -1;
if (isset($_GET['reservering']))
{
$reserveringId = $_GET['reservering'];
}
$row = $this->getReserveringVars($reserveringId);
$klantId = $row['klant_id'];
$rowklant = $this->getKlantVars($klantId);
$row = array_merge($row, $rowklant);
$output = $this->showReserveringForm($row);
return $output;
}
和edit
函数。我希望有人可以帮助我解决这个问题。
目前,这是我的删除功能。当我点击网址中ID为ID的删除按钮时,它会起作用并显示回显
add
答案 0 :(得分:1)
protected function delete()
{
$reserveringId = -1;
if (isset($_GET['reservering']))
{
$reserveringId = $_GET['reservering'];
}
// sql to delete a record
$sql = ("DELETE FROM `reservering` WHERE `reservering`.`reservering_id` = '$reserveringId';");
if ($this->connection->query($sql)) {
$output = "Reservering is succesvol verwijderd";
return $output;
} else {
$output = "Het is niet gelukt om de reservering te verwijderen";
return $output;
}
}
我做到了,感谢您的帮助:)
答案 1 :(得分:0)
示例功能,但您必须学习。
function delete_products($id) {
global $db;
$sql = "DELETE FROM products ";
$sql .= "WHERE id='" . db_escape($db, $id) . "' ";
$sql .= "LIMIT 1";
$result = mysqli_query($db, $sql);
// For DELETE statements, $result is true/false
if($result) {
return true;
} else {
// DELETE failed
echo mysqli_error($db);
db_disconnect($db);
exit;
}
}
OO
public function delete() {
$sql = "DELETE FROM " . static::$table_name . " ";
$sql .= "WHERE id='" . self::$database->escape_string($this->id) . "' ";
$sql .= "LIMIT 1";
$result = self::$database->query($sql);
return $result;