So I am completely new to PHP/MySQL. I basicaly have a html form and I want to use PHP to send all the values to a database. For some reason when I click on submit I only go to a new page where it shows all my PHP code in the browser window. Is this normal? And how can I fix it? Here is my 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>
And my 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));
}
?>
If you do not have a web server configured properly, the PHP would not be executed the way it should be.
Ensure that you have a localhost configured correctly before trying to execute your web app.
If you need a localhost, you could try XAMPP or WAMP for your local machine. If you are going to be using another host, ensure that they have PHP installed on the server.
If you do not want to use a prepackaged server such as the ones above, you can install PHP on your own by following the installation steps on the PHP manual.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With