php代码在表单验证成功后没有执行。我已经在运行XAMPP服务器时运行了代码,但似乎不起作用。我在成功提交表单后在屏幕上看到php代码,而不是让它执行。
``
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Data Entry </title>
<script src="validate.js"></script>
</head>
<body>
<form action="validate.php" method="POST">
<label for="" onfocus="info_name()">Name</label>
<input type="text" id="name" name="name"><br><br>
<label for="" onfocus="info_age()">Age</label>
<input type="number" min="1" name='age' id="age"><br><br>
<label for="" onfocus="info_address()">Address</label>
<input type="text" name="address" id="address"><br><br>
<label for="" onfocus="info_phone()">Phone No.</label>
<input type="text" name="number" id="number"><br><br>
<label for="" onfocus="info_email()">Email Address</label>
<input type="email" name='email' id="email"><br><br>
<p><input type="submit" id="submit" onclick="validate(event)" value="Submit"></p>
</form>
</body>
</html>
<?php
$name=$_POST['name'];
$age=$_POST['age'];
$address=$_POST['address'];
$phone=$_POST['number'];
$email=$_POST['email'];
$conn=new mysqli("localhost",'root','');
if(!$conn){
die("Connection failed".$conn->connect_error);
}
$sql="create database if not exists DATA-ENTRY";
if($conn->query($sql)){
`
2条答案
按热度按时间hivapdat1#
检查您的文件扩展名,它应该以.php结尾
ewm0tg9j2#
PHP代码似乎未被执行,因为它位于HTML代码之后。应在将任何输出发送到浏览器之前执行PHP代码。您可以尝试使用以下代码解决此问题:
?〉