India's No. #1 Programmer's Forum


How to connect MySQL Database with PHP?

Asked by Chandraket On 05 Jun, 2020 09:11:26pm

100

1


Hello Connection,

I want to connect MySQL Database in PHP, when I inserting my data in the database I am facing a problem

Here is My PHP Code



$host = "localhost";
$username = "root";
$password = "";
$db = "test";
if(isset($_POST['insert']))
{

$sql = "insert into student";

if($sql)
{
echo "data insert success";
}else{
echo "some problem";
}

}


Re: How to connect MySQL Database with PHP?

06 Jun, 2020 10:12:48pm
Answer by yuvamind

1

Hello Connection you can use this code, i hop your problem will be solved



$host = "localhost";
$username = "root";
$password = "";
$db = "test";
$con = mysqli_connect($host,$username,$password ,$db);
if(isset($_POST['insert']))
{

$sql = "insert into student set column_name='value'";
$query = mysqli_query($con,$sql);
if($query)
{
echo "data insert success";
}else{
echo "some problem";
}

}





Related Question

CodexEra
Sales Team
sales@codexera.com

Note: If you have a project that you want to get started, launch quickly, contact Us. @9990437464
Talk to us
WhatsApp