-3

I have only recently started with web development and i'm a bit stuck with getting my form information to pull into my db, any suggestions? I have tried various methods.

<?php
$servername="";
$username="";
$password="";
$dbname="";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 

$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>
  • _I have tried various methods_ Really? – AbraCadaver Mar 13 '19 at 15:21
  • 2
    @Lizandre Prinsloo Welcome to SO! Please add your code to the description. See [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – abestrad Mar 13 '19 at 15:24

2 Answers2

0

Not sure what you're calling your inputs. But make sure you have method="post" action="phpDocument.php"
Once you've done that, you could use the print_r() function to and input the $_POST variable. This will show you what data was posted with your form.

Example:

<form method="post" action="exmaple.php">
    <input type="text" name="test" value="123"/>
</form>
print_r($_POST);

print_r() will give you something like:
['test' => 123]

You can then access the data that was submitted by writing:

echo $_POST['test'];

Output:
123

Read more about mysqli here: https://secure.php.net/manual/en/book.mysqli.php

Hope this will help you out, didn't have much to go on ;)

Marh
  • 26
  • 4
0

It is hard to tell what exactly you are looking for. Be sure to be very descriptive with your posts. But here is a link to help you get started. https://www.tutorialrepublic.com/php-tutorial/php-mysql-insert-query.php

Zachary
  • 300
  • 3
  • 11