html+PHP submit form and save to MySQL

I wrote a simple page for collecting information. There is only one form on the page. After the user writes the data into the form and submits it, go to another page and save the data in MySQL.


Information statistics page


<html>
<head>
<meta charset="utf-8">
<meta content="width=device-width,user-scalable=no" name="viewport">
<title>form</title>
<style type="text/css">
	.p1{
		color: black;
		font-size: 30px;
	}
	#box1{
		background-color: #f1861e;
		width: 75%;
		height: 60%;
		float: 0 auto;
		text-align: center;
	}
	#input1{
		width: 100px;
		height: 50px;
		margin: 20px;
	}
	#input0{
		width: 200px;
		height: 30px;
	}
</style>
</head>
<body>
<div style="text-align: center;">
 	<div id="box1">
		<form action="welcome.php" method="post">
			<b class="p1">姓名: </b><input type="text" name="name" id="input0"><br>
			<b class="p1">学号: </b><input type="text" name="num" id="input0"><br>
			<b class="p1">班级:</b><input type="text" name="classl" id="input0"><br>
			<input type="submit" value="提交" id="input1">
		</form>
	</div>
</div>

 
</body>
</html>

Jump to the page after submitting


phpmyadmin page


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
	<title></title>
</head>
<body>
	<?php echo $_POST["num"]; ?><br>
	Welcome <?php echo $_POST["classl"]; ?>
	<?php echo $_POST["name"]; ?>!
	<?php
		$file_path = "info.txt";
		if(file_exists($file_path)){
			$fp = fopen($file_path, "w");
			$str = $_POST["num"] . PHP_EOL . $_POST["classl"] .PHP_EOL . $_POST["name"];
			fwrite($fp, $str);
			
		}
		fclose($fp);
	?>
	<?php
			$mydbhost = "localhost";
			$mydbuser = "root";
			$mydbpass = 'helloworld';
			$conn = mysqli_connect($mydbhost, $mydbuser, $mydbpass);
			if(! $conn){
				die("connect error: " . mysqli_error($conn));
			}
			mysqli_select_db( $conn, 'person');
			$sql="INSERT INTO student (name, Sno, class)
			VALUES
			('$_POST[name]','$_POST[num]','$_POST[classl]')";
			$retval = mysqli_query($conn, $sql);
			if(! $retval){
				die("create error" . mysqli_error($conn));

			}
			mysqli_close($conn);
		?>
</body>
</html>


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325735293&siteId=291194637