Insert Into Database Using PHP MySqli using the following procedures. You must first make sure that you have these steps set up before you proceed.
- You Created A Database
- You Granted Privileges to the database
- Created a config.php file to access the database
- Make sure you Connect to a Database before using this code.
mysqli_query($con,"INSERT INTO table(`row1`, `row2`, `row3`) VALUES ('$var1','$var2','$var3')");
Or you can do it like this.
$sql = "INSERT INTO MyGuests (firstname, lastname, email) VALUES ('John', 'Doe', '[email protected]')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; }
Prepared Statement Insert
$stmt = $conn->prepare("INSERT INTO equipment(`user`, `type`, `name`, `price`,) VALUES (?, ?, ?, ?)"); $stmt->bind_param("issd", $uid, $type, $name, $price); $stmt->execute(); $stme->close();
i=integer
s = string
d = decimal
Insert Into Database Using PHP MySqli
IN the code above you will have to make sure that you change row1, row2, and row3 to match whatever you called your table rows when you created them. Make sure you change the “table” as well so that it matches your database. Last make sure that you change the variables that are going to be inserted into your database. If you need help on PHP Variables please see the post.


A1WEBSITEPRO Social Media Pages
Here are my social media pages, lets hook up!