0

I am creating an airline booking website. I am new to PHP and not extremely familiar with using XAMPP either. I am using Sublime Text 3. User is first brought to a registration form in HTML, when the form is submitted it is supposed to connect to the database using PHP. However, when the form is submitted, it displays the server side code itself instead of executing. I have checked that the php.ini file is in Apache and phpmyadmin is running fine, the PHP code itself is just not executing.

HTML Form

<!DOCTYPE html>
<html lang="en">

<head>
    <title>Login or Register</title>
    <link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>

<body>
<!-- Header -->
    <div class="heading">
        <div class="row">
            <div class="header-title center">
                <big>Average Airlines</big>
            </div>
        </div>
    </div>

<!-- Main Body -->
    <div class="register-box center">
        <div class="register-head text-center">
            No Account? Register Here!
        </div>
        <div class="panel-body">
            <form style="padding:20px" action="connect.php" method="post">
                <div class="form-group" style="padding-bottom: 20px">
                    <label for="fname">First Name<br></label>
                    <input type="text" id="fname" class="form-control" name="fname">
                </div>
                <div class="form-group" style="padding-bottom: 20px">
                    <label for="lname">Last Name<br></label>
                    <input type="text" id="lname" class="form-control" name="lname">
                </div>
                <div class="form-group" style="padding-bottom: 20px">
                    <label for="email">Email<br></label>
                    <input type="text" id="email" class="form-control" name="email">
                </div>
                <div class="form-group" style="padding-bottom: 20px">
                    <label for="address">Billing Address<br></label>
                    <input type="text" id="address" class="form-control" name="address">
                </div>
                <div class="form-group" style="padding-bottom: 20px">
                    <label for="zip">Zipcode<br></label>
                    <input type="text" id="zip" class="form-control" name="zip">
                </div>
                <div class="form-group" style="padding-bottom: 20px">
                    <label for="username">Username<br></label>
                    <input type="text" id="username" class="form-control" name="username">
                </div>
                <div class="form-group" style="padding-bottom: 20px">
                    <label for="password">Password<br></label>
                    <input type="text" id="password" class="form-control" name="password">
                </div>
                <input type="submit" class="btn btn-primary">
            </form>
        </div>
    </div>

<!-- Footer -->
    <div class="footer text-right">
        <small>&copy; Emily Ava</small>
    </div>

</body>
</html>

connect.php

<?php
    ?fname = $_POST['fname'];
    ?lname = $_POST['lname'];
    ?email = $_POST['email'];
    ?address = $_POST['address'];
    ?zip = $_POST['zip'];
    ?username = $_POST['username'];
    ?password = $_POST['password'];

    //Connects to DB
    $conn = new mysqli('localhost', 'root', '', 'userinfo');
    if($conn->connect_error){
        die('Connection Failed : ' $conn->connection_error);
    }
    else {
        //inserts user info into regisration DB table
        $stmt = $conn -> prepare("insert into registration(fname, lname, email, address, zip, username, password) values(?,?,?,?,?,?,?)");
        $stmt -> bind_param("ssssiss",$fname, $lname, $email, $address, $zip, $username, $password);
        echo "Registration Successful!";
        $stmt->close();
        $conn->close();
    }

?>

Emily Ava
  • 1
  • 3
  • In which folder did you put your php file? – Monty Swanson Apr 11 '20 at 19:24
  • `?fname = $_POST['fname'];` this should be --> `$fname = $_POST['fname'];` as I assume you are attempting to assign these post globals to variables correct? – dale landry Apr 11 '20 at 19:25
  • Have you opened the XAMMP control panel and started the APACHE and MYSQL Modules? When you type localhost in your browser does it open the PHP dashboard? – dale landry Apr 11 '20 at 19:31

0 Answers0