这是一款简单利用php mysql把用户提交的信息保存到数据库实例,下面复制文件到你的dw就可以用了,代码如下:
- if( $_post)
- {
- $host = 'localhost';
- $user_name = 'root';
- $password = 'admin';
-
- $name = $_post['user_name'];
- $city = $_post['city'];
-
- if(emptyempty($name) || trim($name)=='')
- {
- echo '请填写用户名!<a href="javascript: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 '数据插入成功,打开查看数据';
- }
- ?>
- 提交用户信息
- <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="提交"></td>
- <td> </td>
- </tr>
- </table>
- </form>
|