phpmysqlundefined-function

Connecting PHP form to MySQL issues


I am trying to learn new things here and I have never worked with PHP nor MySQL. Recently, I installed MySQL on a Linux VM that I have, create some accounts, create a database, a table (firstname, lastname, city, country, age).

Learned how to input data into my table and started inserting stuff using MySQL queries. I quickly realized how ineffective and time consuming it is to enter all this data this way. So I started researching and decided to install PHP on top of IIS on Windows 10 machine I own inside the same network.

Made my SQL database is accessible remotely from my Windows machine and I started following this guide to create my website/forms and connect everything to the MySQL database I already have.

Everything was going smooth until I started adding code to the create.php file in attempt to insert data inside the database after clicking the submit button.

Below is how my create.php looking like now:

<?php

if (isseet($_POST['submit'])) {

  require "../config.php";

  try {
    $connection = new PDO($dsn, $username, $password, $options);
    // insert new user code will go here



$new_user = array(
  "firstname" => $_POST['firstname'],
  "lastname"  => $_POST['lastname'],
  "city"      => $_POST['city'],
  "country"   => $_POST['country'],
  "age"       => $_POST['age']
);

$sql = sprintf(
    "INSERT INTO %s (%s) values (%s)",
    "users",
    implode(", ", array_keys($new_user)),
    ":" . implode(", :", array_keys($new_user))
);

$statement = $connection->prepare($sql);
$statement->execute($new_user);




  } catch(PDOException $error) {
    echo $sql . "<br>" . $error->getMessage();
  }
}
?>


<?php include "templates/header.php"; ?><h2>Add a user</h2>

<form method="post">
        <label for="firstname">First Name</label>
        <input type="text" name="firstname" id="firstname">
        <label for="lastname">Last Name</label>
        <input type="text" name="lastname" id="lastname">
        <label for="city">City</label>
        <input type="text" name="city" id="city">
        <label for="country">Country</label>
        <input type="text" name="country" id="country">
        <label for="age">Age</label>
        <input type="text" name="age" id="age">
        <input type="submit" name="submit" value="Submit">
    </form>

        <a href="index.php">Back to home</a>
            <?php include "templates/footer.php"; ?>

Every time I save and reload the http://localhost/create.php, I get the following error:

PHP Fatal error:  Uncaught Error: Call to undefined function isseet() in C:\inetpub\wwwroot\create.php:3
    Stack trace:
    #0 {main}

thrown in `C:\inetpub\wwwroot\create.php on line 3`

Again, I am very new to this and I am trying my best to make sense of this.


Solution

  • Your first line contains a typo. It should be:

    if (isset($_POST['submit']))

    You had an extra 'e' there.