简体   繁体   中英

HTML submit form and PHP doesn't seem to work

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 .

No, thats probably not normal :)

You probably haven't configured your server to use PHP

First make sure PHP is installed on the server

Then take a look here for how to configure your particular server http://php.net/manual/en/install.php

If you are using a linux based system, your package manager (ie, apt) will usually call the appropriate triggers when you install PHP such that it is automatically integrated into your system.

If you want a full LAMP (linux apache mysql php) stack you can do sudo apt-get install tasksel; sudo tasksel sudo apt-get install tasksel; sudo tasksel and check off 'LAMP Server'. This will guide you through all the setup and configuration

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM