所以我对 PHP/MySQL 完全陌生。我基本上有一个 html 表单,我想使用 PHP 将所有值发送到数据库。出于某种原因,当我单击提交时,我只会转到一个新页面,它会在浏览器窗口中显示我所有的 PHP 代码。这是正常的吗?我该如何解决?这是我的 HTML:
<html>
<body>
<form method="post" action="display.php">
<input name="name" placeholder="Username..."/>
<input name="email" placeholder="Email address..."/>
<input name="date" placeholder="YYYY/MM/DD"/>
<input name="password" placeholder="Password" type="password"/>
<input name="confirm_password" placeholder="Password" type="password"/>
<input type="radio" name="gender" value="male" /> Male<br />
<input type="radio" name="gender" value="female" /> Female
<input type="Submit" value="Submit"/>
</form>
</body>
还有我的 PHP:
<?php
if ($_REQUEST["password"] != $_REQUEST["confirm_password"]){
}else {
$password = $_REQUEST['password'];
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$date = $_REQUEST['date'];
$dns = 'mysql:dbname=mydatabase;host=localhost';
$db = new PDO($dsn, '', '');
$stmt=$db->prepare('INSERT INTO tbUsers(username,email) VALUES ($name,$email)');
$stmt->execute(array($myvalue));
}
?>