Home > Article > Backend Development > PHP code to add records to database_PHP tutorial
The php code for adding records to the database This is a simple way to use php mysql to save the information submitted by users to a database instance. Copy the file to your dw and you can use it.
The database tutorial adds recorded php tutorial code
This is a tutorial that simply uses php mysql to save the information submitted by the user to a database instance. Copy the file to your dw and you can use it.
*/
if( $_post)
{
$host = 'localhost';
$user_name = 'root';
$password = 'admin';
$name = $_post['user_name'];
$city = $_post['city'];
if(empty($name) || trim($name)=='')
{
echo 'Please fill in your username! Return';
exit;
}
$conn = mysql_connect($host,$user_name,$password);
if(!$conn)
{
die('Database connection failed:'.mysql_error());
}
mysql_select_db('test');
$sql = "insert into users set id=7,name='" . $name . "',city='" . $city . "',created_time=now()";
mysql_query($sql) or die("
error: ".mysql_error()."
sql:".$sql);
mysql_close($conn);
echo 'Data insertion successful, open to view data';
}
?>
Submit user information
http: //www.bkjia.com/PHPjc/630824.html
http://www.bkjia.com/PHPjc/630824.html
www.bkjia.com
true