时间:2021-07-01 10:21:17 帮助过:20人阅读
CREATE TABLE `student` (
`id` int(10) unsigned NOT NULL auto_increment,
`xid` varchar(20) NOT NULL,
`name` varchar(20) NOT NULL,
`email` varchar(100) NOT NULL,
`address` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
// 连接数据库
[email protected]_connect("数据库ip","帐号","密码") or die(mysql_error());
@mysql_select_db('数据库名',$conn) or die(mysql_error());
$action = isset($_REQUEST['action'])? $_REQUEST['action'] : '';
if($action=='add'){
$xid = isset($_POST['xid'])? mysql_escape_string($_POST['xid']) : '';
$name = isset($_POST['name'])? mysql_escape_string($_POST['name']) : '';
$email = isset($_POST['email'])? mysql_escape_string($_POST['email']) : '';
$address = isset($_POST['address'])? mysql_escape_string($_POST['address']) : '';
if($xid==''
------解决思路----------------------
$name==''
------解决思路----------------------
$email==''
------解决思路----------------------
$address==''){
echo 'please input data';
exit();
}
$sqlstr = "insert into student(xid,name,email,address) values('".$xid."','".$name."','".$email."','".$address."')";
mysql_query($sqlstr) or die(mysql_error());
header('location:postdemo.php');
}else{
?>
demo
$sqlstr = "select * from student order by id";
$query = mysql_query($sqlstr) or die(mysql_error());
$result = array();
while($thread=mysql_fetch_assoc($query)){
$result[] = $thread;
}
if($result){
echo '
NO | 学生id | 学生名字 | 学生邮箱 | 学生地址 | ';
---|---|---|---|---|
'.$row['id'].' | ';'.$row['xid'].' | ';'.$row['name'].' | ';'.$row['email'].' | ';'.$row['address'].' | ';