php向数据库插入数据
时间:2021-07-01 10:21:17
帮助过:12人阅读
header("Content-type: text/html;charset=utf-8"
);
$con =
mysql_connect("localhost","root","root");
//连接数据库
if (!
$con){
die(‘Could not connect: ‘ .
mysql_error());
}
mysql_select_db("web",
$con);
//打开数据库
mysql_query("set names utf8"
);
$sql="
INSERT INTO users (username, password)
VALUES
(‘$_POST[username]‘,‘
$_POST[password]‘)";
//插入数据
if (!
mysql_query(
$sql,
$con)){
die(‘Error: ‘ .
mysql_error());
echo "0"
;
}
echo "1"
;
mysql_close(
$con);
?>
php向数据库插入数据
标签:text span roo cal color could not close root echo