Why is error occur in line 45 mysqli. and i strictly want to use only mysqli? I tried connection without "new" by creating object it does not works. but when i skip new in connection database line it still does not works fine. please refer me best solution for this Insert, View, edit and delete with mysqli check statement? use
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(isset($_POST['submit'])){
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
// prepare and bind
$prep_stmt = $conn->prepare("INSERT INTO MyGuests (firstname, lastname, email) VALUES (?, ?, ?)");
if($stmt = $conn->prepare($prep_stmt)){
$stmt->bind_param("sss", $firstname, $lastname, $email);
$stmt->execute();
echo "<script>alert('data inserted')</script>";
}
}
?>