php 动态添加记录

yipeiwu_com7年前PHP代码库
复制代码 代码如下:

<html>
<head>
<title>插入一条新数据</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form method="post" name="form1" action="insert.php">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">编号:</td>
<td><input type="text" name="id" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">用户名:</td>
<td><input type="text" name="username" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">密码:</td>
<td><input type="text" name="password" value="" size="32"></td>
</tr>

<tr valign="baseline">
<td colspan="2" nowrap><input name="Submit" type="submit" value="提交">
<input type="reset" name="Reset" value="重设"></td>
</tr>
</table>
</form>
</body>
</html>

复制代码 代码如下:

<?php
@mysql_connect("localhost", "root","1981427") //选择数据库之前需要先连接数据库服务器
or die("数据库服务器连接失败");
@mysql_select_db("test") //选择数据库mydb
or die("数据库不存在或不可用");
$id = $_POST['id'];
$username = $_POST['username'];
$password = $_POST['password'];

$query = mysql_query("insert into tablename1 values($id, '$username', '$password')");
if($query)
echo "数据插入成功";
else
echo "数据插入失败";
mysql_close();
?>

相关文章

js+php实现静态页面实时调用用户登陆状态的方法

本文实例讲述了js+php实现静态页面实时调用用户登陆状态的方法。分享给大家供大家参考。具体分析如下: 在程序开发中,经常会把页面做成html的静态形式,这样可以减轻服务器负载,但是也存...

PHP防CC攻击实现代码

这种时候您的统计系统(可能是量子、百度等)当然也是统计不到的。不过我们可以借助于一些防攻击的软件来实现,不过效果有时并不明显。下面我提供一段PHP的代码,可以起到一定的防CC效果。 主要...

PHP中的strtr函数使用介绍(str_replace)

strtr 有两种形式: string strtr ( string $str , string $from , string $to ) string strtr ( string $...

asp.net访问网络路径方法(模拟用户登录)

核心代码: public class IdentityScope : IDisposable { // obtains user token [DllImport("...

中英文字符串翻转函数

复制代码 代码如下:<?php //页面编码设为utf8 header('Content-type: text/html; charset=utf-8'); $luokuan =...