이 글은 PHP 데이터베이스의 추가, 삭제, 수정 및 쿼리에 대해 공유합니다. 필요한 참조 값이 있습니다.
Register_2018411.php <body> <form name = "frm" action ="insert_2018411.php" method = "post"> Name<input type = "text" name= "txtName"/> <br/> Age<input type = "text" name ="txtAge"/> <br/> Gender <input type = "radio" name ="rdGender" value = "1">Male <input type = "radio" name ="rdGender" value = "0">Female <br/> <input type = "submit" name ="sbtsubmit" value = "Register"/> </form> </body> insert_2018411.php <?php $name = $_POST['txtName']; $age = $_POST['txtAge']; $gender = $_POST['rdGender']; $db =mysqli_connect("localhost","root","1234"); mysqli_select_db($db,"studentdb"); $in="insert intostudentinfotbl(stuName,stuAge,stuGender)values('$name','$age','$gender')"; mysqli_query($db,$in); header("location:show_2018411.php"); ?> show_2018411.php <?php $db =mysqli_connect("localhost","root","1234"); mysqli_select_db($db,"studentdb"); $select = "select * fromstudentinfotbl"; $result = mysqli_query($db,$select); ?> <table border = 1> <tr><td>stuName</td><td>stuAge</td><td>stuGender</td><td>delete</td><td>update</td></tr> <?php while($resArry=mysqli_fetch_array($result)){?> <tr> <td><?phpecho $resArry[1]; ?></td> <td><?phpecho $resArry[2]; ?></td> <td><?php if($resArry[3]==1){ echo"男"; }else{ echo"女"; } ?></td> <td><?phpecho "<a href = 'delete_2018411.php?id=$resArry[0]'> delete</a>"; ?></td> <td><?phpecho "<a href = 'updateFirst.php?id=$resArry[0]'> update</a>"; ?></td> </tr> <?php } ?> </table> delete_2018411.php <?php $db = mysqli_connect("localhost","root","1234"); mysqli_select_db($db,"studentdb"); $id = $_GET['id']; $delete = "delete from studentinfotblwhere stuId = $id"; mysqli_query($db,$delete); header("location:show_2018411.php"); ?> updateFirst.php <?php session_start(); $id = $_GET['id']; echo $id; $_SESSION['id']=$id; ?> <body> <form name = "frm" action ="update_2018411.php" method = "post"> Name<input type = "text" name= "txtName"/> <br/> Age<input type = "text" name ="txtAge"/> <br/> Gender <input type = "radio" name ="rdGender" value = "1">Male <input type = "radio" name ="rdGender" value = "0">Female <br/> <input type = "submit" name ="sbtsubmit" value = "OK"/> </form> </body> update_2018411.php <?php session_start(); $db = mysqli_connect("localhost","root","1234"); mysqli_select_db($db,"studentdb"); $name = $_POST['txtName']; $age = $_POST['txtAge']; $gender = $_POST['rdGender']; $id = $_SESSION['id']; if(1){ $update= "update studentinfotbl setstuName = '$name',stuAge = $age,stuGender = $gender wherestuId =$id;"; mysqli_query($db,$update); } session_destroy(); header("location:show_2018411.php"); ?>
관련 권장 사항:
위 내용은 PHP 데이터베이스 추가, 삭제, 수정 및 쿼리의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!