Warning: Undefined variable $conn in C:xampphtdocsMy Pic Databaseconnect.php on line 20
Fatal error: Uncaught TypeError: mysqli_stmt_init(): Argument #1 ($mysql) must be of type mysqli, null given in C:xampphtdocsMy Pic Databaseconnect.php:20 Stack trace: #0 C:xampphtdocsMy Pic Databaseconnect.php(20): mysqli_stmt_init(NULL) #1 {main} thrown in C:xampphtdocsMy Pic Databaseconnect.php on line 20
HTML CODE----->
<form action="connect.php" method="post">
<div class="lg:w-1/2 md:w-2/3 mx-auto">
<div class="flex flex-wrap -m-2">
<div class="p-2 w-1/2">
<div class="relative">
<label for="name" class="leading-7 text-sm text-gray-600">Name</label>
<input type="text" id="name" name="name" class="w-full bg-gray-100 bg-opacity-50 rounded border border-gray-300 focus:border-indigo-500 focus:bg-white focus:ring-2 focus:ring-indigo-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 transition-colors duration-200 ease-in-out">
</div>
</div>
<div class="p-2 w-1/2">
<div class="relative">
<label for="email" class="leading-7 text-sm text-gray-600">Email</label>
<input type="email" id="email" name="email" class="w-full bg-gray-100 bg-opacity-50 rounded border border-gray-300 focus:border-indigo-500 focus:bg-white focus:ring-2 focus:ring-indigo-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 transition-colors duration-200 ease-in-out">
</div>
</div>
<div class="p-2 w-1/2">
<div class="relative">
<label for="phone" class="leading-7 text-sm text-gray-600">Phone</label>
<input type="phone" id="phone" name="phone" class="w-full bg-gray-100 bg-opacity-50 rounded border border-gray-300 focus:border-indigo-500 focus:bg-white focus:ring-2 focus:ring-indigo-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 transition-colors duration-200 ease-in-out">
</div>
</div>
<div class="p-2 w-1/2">
<div class="relative">
<label for="pack" class="leading-7 text-sm text-gray-600">Pack</label>
<select id="pack" name="pack" required class="w-full bg-gray-100 bg-opacity-50 rounded border border-gray-300 focus:border-indigo-500 focus:bg-white focus:ring-2 focus:ring-indigo-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 transition-colors duration-200 ease-in-out">
<option value="select">Select</option>
<option value="start">Start</option>
<option value="pro">PRO</option>
<option value="business">Business</option>
<option value="special">Special</option>
</select>
</div>
</div>
<div class="p-2 w-full">
<div class="relative">
<label for="message" class="leading-7 text-sm text-gray-600">Message</label>
<textarea id="message" name="message" class="w-full bg-gray-100 bg-opacity-50 rounded border border-gray-300 focus:border-indigo-500 focus:bg-white focus:ring-2 focus:ring-indigo-200 h-32 text-base outline-none text-gray-700 py-1 px-3 resize-none leading-6 transition-colors duration-200 ease-in-out"></textarea>
</div>
</div>
<div class="p-2 w-full">
<button class="flex mx-auto text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-none hover:bg-indigo-600 rounded text-lg">Submit</button>
</div>
</form>
PHP CODE----->
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$phone = filter_input(INPUT_POST,"phone",FILTER_VALIDATE_INT);
$pack = $_POST["pack"];
$message = $_POST["message"];
$host="localhost";
$dbname="myfirstpic";
$username="root";
$password="";
mysqli_connect($host, $username, $password, $dbname);
if(mysqli_connect_errno()){
die("Connection error: " . mysqli_connect_error());
}
$sql="INSERT INTO message (name, email, phone, pack, message)
VALUES(?,?,?,?,?)";
$stmt=mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt,$sql)){
die(mysqli_error($conn));
}
mysqli_stmt_bind_param($stmt,"ssiss",
$name,
$email,
$phone,
$pack,
$message);
mysqli_stmt_execute($stmt);
echo "Record Saved.";
?>
i am trying to get contact us information of my project site into database