PHP development student management system add information PHP page
Receive the data passed from the add.php page and save the data to the database
Tip: This tutorial is to The PHP code for adding, modifying, and deleting is placed on the same PHP page. We used switch and case statements. The following code is the incomplete action.php file code. When we complete the adding, modifying, and deleting functions, it will Show the complete code to everyone
Link to our database first
$conn=mysqli_connect("localhost","root","root","study");
mysqli_set_charset($conn,"utf8");
Receive the data we pass from the add page Incoming information
$sex = $_POST['sex'];
$age = $_POST['age'] ;
$class = $_POST['class'];
Inserting data into our database
$rw = mysqli_query($conn,$sql);
The code to add information is as follows
<?php
header("content-type:text/html;charset=utf8");
$conn=mysqli_connect("localhost","root","root","study");
mysqli_set_charset($conn,"utf8");
if($conn){
switch ($_GET['action']){
case 'add'://add
$name = $_POST['name'];
$sex = $_POST['sex'];
$age = $_POST['age'];
$class = $_POST['class'];
$sql = "insert into stu (`name`, sex, age, class) values ('$name', '$sex','$age','$class')";
$rw = mysqli_query($conn,$sql);
if ($rw > 0){
echo "<script>alert('添加成功');</script>";
}else{
echo "<script>alert('添加失败');</script>";
}
}
}
header('Location: index.php');
break;
?>The next step is to display the information we added
##
















The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~ 