Home > Backend Development > PHP Tutorial > PHP code to add records to database_PHP tutorial

PHP code to add records to database_PHP tutorial

WBOY
Release: 2016-07-13 17:04:58
Original
928 people have browsed it

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



                                                                                                                                                                                                                                                                                                
               
                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                       
                                                                    
                                                                                       
Username: From city:  






http://www.bkjia.com/PHPjc/630824.html

www.bkjia.com

true
http: //www.bkjia.com/PHPjc/630824.html

TechArticleThe php code for adding records to the database. This is a simple use of php mysql to save the information submitted by the user to the database instance. , copy the file to your dw and you can use it. Database teaching...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template