如何从数据库中搜索某个 ID?然后,如果它不存在,它应该告诉我找不到该 id,如果它存在,它应该告诉我,例如“该 id 已成功删除”。
这是我的代码:这是我用来删除项目的代码,它正在删除,但是当我输入一个不存在的 ID 时,什么都没有出现:
<!-- THIS IS MY DATABASE CONNECTOR/I SAVED IT AS (dbconn.php) -->
<?php
$hostname="localhost";
$username="root";
$password="";
$conn=mysql_connect($hostname,$username,$password);
if(!conn){
die("There is no connection to the mysql server".mysql_error());
}
$mysql_db=mysql_select_db("djwriters", $conn);
if(!$mysql_db){
die("There is no database onnection". mysql_error());
}
?>
<!-- THIS IS WHERE IS INPUT A TEXTBOX AND A DELETE BUTTON.
I saved it as (tash.php) -->
<body>
<table width="840">
<tr>
<td>
<form action="reason.php" method="post" name="frmreason">
<label>ID:</label><input name="ID" type="text" />
<input type="submit" name="delete" id="Delete" value="Delete" />
</form>
</td>
</tr>
</table>
</body>
<!-- THIS IS NOW THE CODE THAT I USED TO DELETE THE ROW.
I saved it as (delete.php) -->
<?php
include("dbconn.php");
if(isset($_POST['delete'])and $_POST['ID']){
$sql="DELETE FROM `djwriters`.`personal` WHERE `personal`.`ID` ='$_POST[ID]'";
mysql_query($sql) or die("The id was not found".mysql_error());
}
?>
有人会帮助我吗?当您单击删除按钮时,代码应该从数据库中搜索一个项目,如果它enter code here
不存在,它应该向我显示或显示一个错误,如果它enter code here
应该告诉我已成功删除。isset
在 PHP 中使用函数