
首先,你得在diaocha.php这个文件,接收表单传的值
$radiogroup = isset($_POST['radiogroup'])?$radiogroup:'' $con = mysql_connect('localhost','root','')//三个参数,分别是,连接的主机名,mysql的账号,mysql密码mysql_query('set names utf8')//设置连接的字符集,如果页面是utf8的编码,就是utf8,如果是gbk的话,那就写 set names gbk
mysql_select_db('xxx',$con)&nbsp//xxx就是你要选择的数据库名称
插入数据
$sql = "insert into xxxx set xxx = $radiogroup" //xxxx 是你要插入的表名,xxx就是字段名 mysql_query($sql)把下面的代码保存为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$hostName = 'yourhost'
$userName = 'yourusername'
$passWords = 'yourpwd'
$conn = mysql_conn($hostName,$userName,$passWords)
if(!$conn){
die('Could not connect: ' . mysql_error())
}
$mysql_select_db('admin',$conn)
$sql="INSERT INTO user_zy (username, name, time,place,type,http,password)
VALUES
('$_POST[username]','$_POST[name]','$_POST[time]','$_POST[place]','$_POST[type]',
'$_POST[http]','$_POST[password]')"
mysql_query($sql,$conn) //这里是添加数据。
//读取数据
$sql = "select * form user_zy where 1" //读取所有。
$sql = "select * form user_zy where id=".$id //读取某一项。
$result = mysql_query($sql,$conn)
while($info = mysql_fetch_array($result)){
$arr[] = $info //$arr 为最后所要读取的值。
}
可以用var_dump($arr)打印出来看看。
有什么不明白可以留言。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)