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
Receive the data we pass from the add page Incoming information
Inserting data into our database
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