PHP 데이터베이스 추가, 삭제, 수정 및 쿼리

不言
풀어 주다: 2023-03-23 19:48:02
원래의
1856명이 탐색했습니다.

이 글은 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[&#39;txtName&#39;];
$age = $_POST[&#39;txtAge&#39;];
$gender = $_POST[&#39;rdGender&#39;];
 
$db =mysqli_connect("localhost","root","1234");
mysqli_select_db($db,"studentdb");
 
$in="insert intostudentinfotbl(stuName,stuAge,stuGender)values(&#39;$name&#39;,&#39;$age&#39;,&#39;$gender&#39;)";
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 = &#39;delete_2018411.php?id=$resArry[0]&#39;> delete</a>";  ?></td>
         <td><?phpecho "<a href = &#39;updateFirst.php?id=$resArry[0]&#39;> update</a>";  ?></td>
</tr>
 
<?php
}
?>
 
</table>
 
 
 
 
 
 
 
 
delete_2018411.php
 
<?php
 
$db = mysqli_connect("localhost","root","1234");
mysqli_select_db($db,"studentdb");
 
$id = $_GET[&#39;id&#39;];
$delete = "delete from studentinfotblwhere stuId = $id";
mysqli_query($db,$delete);
 
header("location:show_2018411.php");
 
?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
updateFirst.php
 
<?php
session_start();
$id = $_GET[&#39;id&#39;];
echo $id;
$_SESSION[&#39;id&#39;]=$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[&#39;txtName&#39;];
$age = $_POST[&#39;txtAge&#39;];
$gender = $_POST[&#39;rdGender&#39;];
 
$id = $_SESSION[&#39;id&#39;];
 
if(1){
         $update= "update  studentinfotbl setstuName = &#39;$name&#39;,stuAge = $age,stuGender = $gender
         wherestuId =$id;";
         mysqli_query($db,$update);
        
}
 
session_destroy();
 
header("location:show_2018411.php");
 
?>
로그인 후 복사

관련 권장 사항:

PHP 데이터베이스 저장 세션 세션



위 내용은 PHP 데이터베이스 추가, 삭제, 수정 및 쿼리의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!