Insert data into mysql table in php using mysqli method

Create File first.php using form

<style>
    input{
        display: block;
    }
    </style>
    <form method="post" action="second.php" enctype="multipart/form-data">
<input type="text" name="user_name">
<input type="password" name="user_password">

Male <input type="radio" name="gender" value="male" checked>
Female <input type="radio" name="gender" value="female">

<input type="checkbox" name="car" value="Maruti"> Car 
<input type="checkbox" name="house" value="Narela"> House 
<input type="checkbox" name="bike" value="Bajaj"> Bike 

<input type="file" name="image[]" multiple>

<input type="submit" value="Click" name="click">
</form>

Create file second.php to insert data into table

this example show only two fields, you can add more field in php code to insert.

<?php
$host="localhost";
$user="root";
$password="";
$database="pankaj";


$link= mysqli_connect($host, $user, $password, $database);
if(!$link)
{
    echo "Not Connected".mysqli_error($link);
    die();
}

$user_name=$_POST['user_name'];
$user_Password=$_POST['user_password'];

$cmd="insert into user  set user_name='$user_name', user_password='$user_Password'";
if(mysqli_query($link, $cmd))
{
 echo "Success";   
}
else
{
    echo "User Already Exists";//mysqli_error($link);
}




?>



Leave a Reply