php 資料庫的增刪改查

來源:互聯網
上載者:User

標籤:ids   title   ==   start   border   meta   order   hidden   資料庫   

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
$db= new Mysqli("localhost","root","root","asd_8080");
//empty(mysqli_connect_error())?"":die("串連錯誤");


$sql="select * from user where is_delete=‘0‘";
$data= $db->query($sql)->fetch_all();
if (!empty($_POST)){
$name = $_POST[‘name‘];
$sex = $_POST[‘sex‘];
$birth_start=$_POST[‘birth_start‘];
$birth_end = $_POST[‘birth_end‘];

$sql .= !empty($name)? "and name like ‘%{$name}%‘":"";
$sql .= !empty($sex)? "and sex like ‘%{$sex}%‘":"";
}



?>
<form action="mxdx2.php" method="post">
<table>
<tr>
<td>姓名:<input type="text" name="name"></td>
<td>性別:
<select name="sex">
<option value="1">男</option>
<option value="0">女</option>
</select>
</td>
<td>
年齡:<input type="text" name="birth_start">---<input type="text" name="birth_end">
</td>
<td>
<input type="submit" value="查詢">
</td>
</tr>
</table>
</form>
<form action="plsc.php" method="post">
<table border="1">
<form border="2">
<tr>
<td>ID</td>
<td>姓名</td>!
<td>性別</td>
<td>年齡</td>
<td>出生年月</td>
</tr>
<?php
foreach ($data as $i){
if ($i[2]== 1 ){
$i[2]="男";
}else if ($i[2]== 0 ){
$i[2]="女";
}else{
$i[2]="保密";
}
echo "<tr><td>{$i[0]}<input type=‘checkbox‘ name=‘ids[]‘ value=‘{$i[0]}‘></td><td>{$i[1]}</td><td>{$i[2]}</td><td>{$i[3]}</td><td>{$i[4]}</td><td><a href=‘mxdx3.php?id={$i[0]}‘>刪除</a></td>&nbsp;&nbsp;<td><a href=‘edit.php?id={$i[0]}‘>修改</a></td></tr>";
}
?>


</table>
<input type="submit" value="大量刪除">
</form>
<a href="add.php">新增使用者</a>

</body>
</html>



<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form method="post" action="addpost.php">
<input type="text" name="name">
<input type="radio" name="sex" value="1" id="man" ><label for="man">男</label>
<input type="radio" name="sex" value="0" id="woman" ><label for="woman">女</label>
<input type="text" name="age" placeholder="年齡">
<input type="text" name="create_time" placeholder="出生年月">
<input type="submit" value="提交">
</form>

</body>
</html>

<?php
$name = $_POST[‘name‘];
$sex = $_POST[‘sex‘];
$age=$_POST[‘age‘];
$birthday = $_POST[‘create_time‘];


$db = new Mysqli("localhost","root","root","asd_8080");
$sql = "INSERT INTO user VALUES (NULL ,‘{$name}‘,{$sex},‘{$age}‘,{$birthday},‘0‘)";
if($db->query($sql)){
header("location:mxdx2.php");
}else{
header("location:add.php");
}



<?php
$id = $_GET[‘id‘];

$db= new Mysqli("localhost","root","root","asd_8080");
mysqli_connect_error()?die("串連出錯"):"";
$sql = "delete from USER WHERE id = {$id}";
$sql2 = "update user set is_delete =‘1‘ WHERE id ={$id}";
if ($db->query($sql2)){
header("location:mxdx2.php");

}



<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="editpost.php" method="post">
<input type="hidden" name="id" value="<?php echo $data[‘id‘]?>">
<input type="text" name="neme" value="<?php echo $data[‘neme‘]?>">
<input type="radio" name="sex" value="1" <?php if ($data[‘sex‘]==1){echo ‘checked‘;}?> id="man" ><label for="man">男</label>
<input type="radio" name="sex" value="0" <?php if ($data[‘sex‘]==0){echo ‘checked‘;}?> id="woman" ><label for="woman">女</label>
<input type="text" name="age" value="<?php echo $data[‘age‘]?>" placeholder="年齡">
<input type="text" name="create_time" placeholder="出生年月" value="<?php echo $data[‘create_time‘]?>">
<input type="submit" value="提交">
</form>

</body>
</html>


<?php
$id=$_POST[‘id‘];
$name = $_POST[‘neme‘];
$sex = $_POST[‘sex‘];
$age=$_POST[‘age‘];
$birthday = $_POST[‘create_time‘];
var_dump($name);
$db= new Mysqli("localhost","root","root","asd_8080");
$sql = "update `user` set neme=‘{$name}‘,sex=‘{$sex}‘,age ={$age},create_time=‘{$birthday}‘WHERE id={$id}";
if ($db->query($sql)){
echo "執行成功";
}






php 資料庫的增刪改查

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.