0

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.

Obmerk Kronen
  • 15,619
  • 16
  • 66
  • 105
simo110
  • 15
  • 5
  • 1
    What have you tried to debug the problem? As the error tells you, there might be an error on line 3, so maybe you want to check that line for a typo? ;) – Nico Haase Nov 22 '19 at 08:46

1 Answers1

2

Your first line contains a typo. It should be:

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

You had an extra 'e' there.

Paulo Hgo
  • 834
  • 1
  • 11
  • 26
  • Thanks, I can't believe I missed that one. Form is displaying properly now, I filled out the info and clicked submit, and I am getting the error below: PHP Warning: require(../config.php): failed to open stream: No such file or directory in C:\inetpub\wwwroot\create.php on line 5 PHP Fatal error: require(): Failed opening required '../config.php' (include_path='.;C:\php\pear') in C:\inetpub\wwwroot\create.php on line 5 – simo110 Nov 22 '19 at 04:41
  • @simo110 The error is very clear, your path to `config.php` is wrong. I suggest reading about the errors and understanding them – Carl Binalla Nov 22 '19 at 04:43
  • I'd love to understand the down vote... should it have been just a comment? And yes, you need to understand basic PHP error messages first. Your file is not in the location your code expects it. – Paulo Hgo Nov 22 '19 at 04:45
  • Yea I just took care of the path issue just now. As I mentioned already guys, i'm very new to this and learning along the while working on this little project. I am now getting a new error message after clicking submit, but I will try to research some more and see if I can fix it. – simo110 Nov 22 '19 at 04:57
  • I am now getting something about "undefined variable" in line 35. Line 35 looks like this: echo $sql . "
    " . $error->getMessage(); but I see in the file that it is already defined using the $sql = sprintf(.....
    – simo110 Nov 22 '19 at 05:32
  • @simo110 If you encounter other problems Please open another question. this one was already answered and accepted. and please read and understand the error messages and search for existing answers regarding same errors if possible. – Obmerk Kronen Nov 22 '19 at 07:22