mysql 查询调试_mysql的一个基础查询

前台html

math

china

music

pe

php根据前台提交的数据查找mysql的数据

数据库中已经有一个名为book的数据表,字段分别有type,author 和time

$type=$_POST['type'];

//链接数据库

$db=new mysqli('localhost','root','','books');

//检测是否链接成功

if(mysqli_connect_erron()){

echo 'error connect to mysql server';

exit;

}

//查询语句

$query="select * from book where type='".$type."'";

//执行查询

$result=$db->query($query);

//返回结果的行数

$num_result=$result->num_rows;

//循环输出结果的内容

for($i=0;$i

$rows= $result->fetch_assoc();

echo $rows['type'].'
';

echo $rows['author'].'
';

echo $rows['time'];

}

// 释放结果集

$result->free();

//关闭数据库

$db->close();

?>

php根据前台输入的数据向数据库添加数据

$type=trim($_POST['type']);

$author=trim($_POST['author']);

$time=trim($_POST['time']);

if(!$type || !$author || !$time){

echo 'plz enter the full ';

exit;

}

if(!get_magic_quotes_gpc()){

$type=addslashes($type);

$author=addslashes($author);

$time=addslashes($time);

}

$db=new mysqli('localhost','root','','books');

if(mysqli_connect_erron()){

echo 'cant connect to mysql server';

exit;

}

$query="insert into book values ('".$type."','".$author."','".$time."')";

$result=$db->query($query);

if($result){

echo $db->affected_rows.'books insert into databases';

}else{

echo 'an error occurred';

}

$db->close();

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值