数据库为test下有一个表 reguser,表结构如下
+---------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+----------------+
| sex | char(2) | NO | | | |
下为表单提交的1.html
<html><body>
<form action=1.php method="POST">
性别:<input type="radio" name="sex" value="男" checked>男<input type="radio" name="sex" value="女">女
</body></html>这个为提交到服务端的1.php<?php
//连接到本地mysql数据库
$myconn=mysql_connect("localhost","root","123456");
mysql_select_db("test",$myconn);
$sex = $_POST['sex'];
//将用户填写信息添加到数据库
$strSql="insert into test.reguser (sex) values ('$sex');";
$result=mysql_query("$strSql",$myconn) or die(mysql_error());
//关闭对数据库的连接
mysql_close($myconn);
?>
但老是有错,大家可否帮着提供个范例,谢谢了。
+---------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+----------------+
| sex | char(2) | NO | | | |
下为表单提交的1.html
<html><body>
<form action=1.php method="POST">
性别:<input type="radio" name="sex" value="男" checked>男<input type="radio" name="sex" value="女">女
</body></html>这个为提交到服务端的1.php<?php
//连接到本地mysql数据库
$myconn=mysql_connect("localhost","root","123456");
mysql_select_db("test",$myconn);
$sex = $_POST['sex'];
//将用户填写信息添加到数据库
$strSql="insert into test.reguser (sex) values ('$sex');";
$result=mysql_query("$strSql",$myconn) or die(mysql_error());
//关闭对数据库的连接
mysql_close($myconn);
?>
但老是有错,大家可否帮着提供个范例,谢谢了。
不要数据库名
然后echo $strsql试试