Tumgik
#phpphp developmentphp tutorialphp programminglearn php
skptricks · 7 years
Text
PHP Insert Data Into MySQL
In this post, we are going to learn how to insert records in database table using PHP Script. To insert records in database table we are using PHP mysql_query() function. This function is used to perform query operation in MySQL database. Before we start with insert operation in MySQL database, I think we should have complete idea about how to create MySQL database table using PHP script. NOTE : mysql_query() function is deprecated, since PHP 5.5 Version. PHP MySQLi Insert Record Example
<?php $host = 'localhost'; // set hostname $user = ''; // set mysql username $pass = ''; // set mysql password $dbname = 'companyrecord'; // establish database connection $conn = mysqli_connect($host, $user, $pass,$dbname); if(!$conn){ die('Could not connect: '.mysqli_connect_error()); } echo 'Connected to database successfully<br/>'; // query to perform $sql = 'INSERT INTO employee(empname,empsalary) VALUES ("skptricks", 104000)'; // performing the query in database if(mysqli_query($conn, $sql)){ echo "Record inserted successfully in database"; }else{ echo "Could not insert record: ". mysqli_error($conn); } mysqli_close($conn); ?>
Output: ----------------------- Connected to database successfully Record inserted successfully in database
via Blogger http://ift.tt/2wHY4l1
0 notes