连接数据库的代码是:
淮阳网站建设公司成都创新互联,淮阳网站设计制作,有大型网站制作公司丰富经验。已为淮阳千余家提供企业网站建设服务。企业网站搭建\成都外贸网站建设要多少钱,请找那个售后服务好的淮阳做网站的公司定做!
?php
mysql_connect('数据库ip地址','用户名','密码');
mysql_select_db('数据库名');
?
把下面的代码保存为post.php
?
$conn = mysql_connect("localhost","11111","22222");
$action = $_POST['action'];
if($action == 'send'){
$username = $_POST['username'];
$password = $_POST['password'];
mysql_select_db("333333",$conn);
$sql = "INSERT INTO player (username,password) VALUES ('$username','$password')";
$result = mysql_query($sql,$conn);
}
?
html
body
form method="post" action="post.php"
input type="text" name="username"
input type="text" name="password"
input type="hidden" name="action" value="send"
input type="submit" name="Submit" value="提交"
/form
/body
/html
读数据库,以表格输出的示例代码:
?php
header('Content-type:text/html;charset=utf-8');
$db = new mysqli('localhost','root','root','books');
$rows = $db-query('SELECT * FROM customers');
echo 'table border="1"trtd姓名/tdtd年龄/td/tr';
while($row = $rows-fetch_assoc()){
echo 'trtd'.$row['name'].'/td';
echo 'td'.$row['address'].'/td/tr';
}
?