0

The problem is in insertRecord.php but i am unable to find it.i have also attached the image of error

The problem is in insertRecord.php but i am unable to find it.i have also attached the image of error

Undefined variable: firstname,lastname,password,email,age,gender is the problem enter image description here

insertRecord.php

<?php
    include 'connection.php';
    if(isset($_POST['submit']))
    {
        echo"sucee";
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $gender = $_POST['gender'];
    $age = $_POST['age'];
    }

    $sql = "INSERT INTO user (FirstName,LastName,Email,Password,Gender,Age) VALUES ('$firstname', '$lastname', '$email', '$password', '$gender', '$age')";


    $result=mysqli_query($connection, $sql);
    include 'watWK6.php';
    include 'selectRecord.php';


    ?>

connection

<?php 
$hostname = 'localhost'; 
$username = 'root'; 
$password = ''; 
$databaseName = 'c7181378'; 
$connection = mysqli_connect($hostname, $username, $password, $databaseName) or exit("Unable to connect to database!");
?>

watWK6.php

<!DOCTYPE html>
<html lang="en">
   <head>
      <title>Web Applications and Technologies</title>
      <link type="text/css" rel="stylesheet" href="main.css" />
   </head>
   <body>
      <header>
         <h1> C7181378</h1> 
      </header>

      <section id="container">
         <form method = "POST" action = "insertRecord.php">
            <fieldset>
                <legend> Enter Customer Details </legend>
                <label> First Name: </label>
                <input type = "text" name = "firstname"/>
                <br/>
                <label> Surname: </label>
                <input type = "text" name = "lastname"/>
                <br/>
                <label> Email: </label>
                <input type = "text" name = "email"/>
                <br/>
                <label> Password: </label>
                <input type = "password" name = "password"/>
                <br/>
                <label> Gender: </label>
                <select name = "gender">
                    <option value = "M"> Male </option>
                    <option value = "F"> Female </option>
                </select>
                <br/>
                <label> Age: </label>
                <input type = "text" name = "age"/>
                <br/>
                <input type = "submit" value = "submit" name = "submit"/>
            </fieldset>
         </form>
      </section>
      <footer>   
         <small> <a href="../index.html">Home</a></small>
      </footer>
   </body>
</html>

<?php
    include 'selectRecord.php';
?>
mega6382
  • 9,211
  • 17
  • 48
  • 69
Prayas Bhari
  • 55
  • 2
  • 9
  • 3
    Move your query part inside `if` statement – M Khalid Junaid Nov 27 '17 at 07:24
  • 2
    Don't use the deprecated and insecure **mysql*-functions**. They have been **deprecated** since PHP 5.5 (in 2013) and were completely removed in PHP 7 (in 2015). Use MySQLi or PDO instead. 2. You are wide open to **[SQL Injections](http://php.net/manual/en/security.database.sql-injection.php)** and should really use [Prepared Statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) instead of concatenating your queries, which can be used if you use the above mentioned MySQLi or PDO. – Milan Chheda Nov 27 '17 at 07:31

1 Answers1

0

Please make changes in insertRecord.php Note : Don't use the deprecated and insecure mysql*-functions as Milan Chheda said in comment

<?php
    include 'connection.php';
    if(isset($_POST['submit']))
    {
        echo"sucee";
        $firstname = $_POST['firstname'];
        $lastname = $_POST['lastname'];
        $email = $_POST['email'];
        $password = $_POST['password'];
        $gender = $_POST['gender'];
        $age = $_POST['age'];
        $sql = "INSERT INTO user (FirstName,LastName,Email,Password,Gender,Age) VALUES ('$firstname', '$lastname', '$email', '$password', '$gender', '$age')";

        $result=mysqli_query($connection, $sql);

    }

    include 'watWK6.php';
    include 'selectRecord.php';


    ?>
rahul
  • 776
  • 5
  • 30