代码如下 | 复制代码 |
if( $_post) { $host = 'localhost'; $user_name = 'root'; $password = 'admin'; $name = $_post['user_name']; $city = $_post['city']; if(empty($name) || trim($name)=='') { echo '请填写用户名!<a href="网页特效:histryback();">返回</a>'; exit; } $conn = mysql_connect($host,$user_name,$password); if(!$conn) { die('数据库连接失败:'.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("<br/>error: <b>".mysql_error()."</b><br/>sql:".$sql); mysql_close($conn); echo '数据插入成功,打开查看数据'; } |
?>
<b>提交用户信息</b>
代码如下 | 复制代码 |
<form name="form" method="post" action=""> <table width="75%" border="0" cellpadding="0" cellspacing="2"> <tr> <td width="24%" height="29">用户名:</td> <td width="76%"><input name="user_name" type="text" id="user_name" size="20"></td> </tr> <tr> <td height="25">来自城市:</td> <td> <select name="city"> <option value="beijing">北京</option> <option value="london">伦敦</option> <option value="newyork">纽约</option> <option value="paris">巴黎</option> <option value="rome">罗马</option> </select> </td> </tr> <tr> <td height="31"> <input type="submit" name="submit" value="提交www.111cn.net"></td> <td> </td> </tr> </table> </form> |
时间: 2024-10-09 22:36:17