php提交查询数据 用php查询数据库信息

php数据查询和数据插入

?php

创新互联公司主要业务有网站营销策划、成都网站设计、网站制作、微信公众号开发、微信小程序开发、H5响应式网站、程序开发等业务。一次合作终身朋友,是我们奉行的宗旨;我们不仅仅把客户当客户,还把客户视为我们的合作伙伴,在开展业务的过程中,公司还积累了丰富的行业经验、营销型网站资源和合作伙伴关系资源,并逐渐建立起规范的客户服务和保障体系。 

$con = mysql_connect("localhost","用户名","密码");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("数据库", $con);

$result = mysqli_query("SELECT 字段名 FROM 表名 where 字段名=判断的变量");

if(mysqli_num_rows(result) 0)

{

echo "用户名已存在";

} else {

mysqli_query("inset语句");

}

mysqli_close($con);

?

PHP 通过提交 查询到的数据,怎么将这数据作为条件 用与另一表单查询呀

这个架设2张关联数据表。

第一张表记录每本书的isbn,条形码,书名,价格。

第二张表记录,每次借书的信息,包含:借书条码,借的书isbn,借书时间,读者卡号

然后再搜索栏输入读者卡号,使用sql的管理查询,查询第二张表的读者卡号,就能看到所列的信息了。

全部在一个表单当然不合理,每本书的信息会重复很多,导致数据库冗余。因为会有不同人借同一本书,每次借书记录只要记录数的id,和读者id就可以了。当然,每次显示,需要再次显示书的的信息和读者信息,这时可以用关联查询,或者使用缓存记录相关信息避免对数据库查询太多。

PHP怎么获取表单提交的数据啊?

一、用file_get_contents以get方式获取内容,需要输入内容为:

1、?php

2、$url='';

3、$html=file_get_contents($url);

4、echo$html;

5、?

二、用file_get_contents函数,以post方式获取url,需要输入内容为

1、?php

2、$url='';

3、$data=array('foo'='bar');

4、$data=http_build_query($data);

5、$opts=array(

6、'http'=array(

7、 'method'='POST',

8、 'header'="Content-type:application/x-www-form-urlencoded\r\n".

9、          "Content-Length:".strlen($data)."\r\n",

10、 'content'=$data

11、)

12、);

13、$ctx=stream_context_create($opts);

14、$html=@file_get_contents($url,'',$ctx);

15、?

三、用fopen打开url,以get方式获取内容,需要输入内容为

1、?php

2、$fp=fopen($url,'r');

3、$header=stream_get_meta_data($fp);//获取信息

4、while(!feof($fp)){

5、$result.=fgets($fp,1024);

6、}

7、echo"urlheader:{$header}br":

8、echo"urlbody:$result";

9、fclose($fp);

10、?

四、用fopen打开url,以post方式获取内容,需要输入内容为

1、?php

2、$data=array('foo2'='bar2','foo3'='bar3');

3、$data=http_build_query($data);

4、$opts=array(

5、'http'=array(

6、'method'='POST',

7、'header'="Content-type:application/x-www-form-urlencoded\r\nCookie:cook1=c3;cook2=c4\r\n".

8、"Content-Length:".strlen($data)."\r\n",

9、'content'=$data

10、)

11、);

12、$context=stream_context_create($opts);

13、$html=fopen(';id2=i4','rb',false,$context);

14、$w=fread($html,1024);

15、echo$w;

16、?

五、用fsockopen函数打开url,以get方式获取完整的数据,包括header和body,需要输入内容为

1、?php

2、functionget_url($url,$cookie=false)

3、{

4、$url=parse_url($url);

5、$query=$url[path]."?".$url[query];

6、echo"Query:".$query;

7、$fp=fsockopen($url[host],$url[port]?$url[port]:80,$errno,$errstr,30);

8、if(!$fp){

9、returnfalse;

10、}else{

11、$request="GET$queryHTTP/1.1\r\n";

12、$request.="Host:$url[host]\r\n";

13、$request.="Connection:Close\r\n";

14、if($cookie)$request.="Cookie:  $cookie\n";

15、$request.="\r\n";

16、fwrite($fp,$request);

17、while(!@feof($fp)){

18、$result.=@fgets($fp,1024);

19、}

20、fclose($fp);

21、return$result;

22、}

23、}

24、//获取url的html部分,去掉header

25、functionGetUrlHTML($url,$cookie=false)

26、{

27、$rowdata=get_url($url,$cookie);

28、if($rowdata)

29、{

30、$body=stristr($rowdata,"\r\n\r\n");

31、$body=substr($body,4,strlen($body));

32、return$body;

33、}

34、 returnfalse;

35、}

36、?

参考资料:

php-file_get_contents

PHP同一个页面通过提交按钮提交条件查询数据库时,默认查询全部数据

写个function呀,调用function显示数据。

我给你举个例子你看下:吧下面的代码粘贴运行,您就会秒懂:

html

head

/head

body 

?php

$name = $email = $gender = $comment = $website = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$name = test_input($_POST["name"]);

$email = test_input($_POST["email"]);

$website = test_input($_POST["website"]);

$comment = test_input($_POST["comment"]);

$gender = test_input($_POST["gender"]);

}

function test_input($data) {

$data = trim($data);

$data = stripslashes($data);

$data = htmlspecialchars($data);

return $data;

}

?

h2PHP 验证实例/h2

form method="post" action="?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?"

姓名:input type="text" name="name"

brbr

电邮:input type="text" name="email"

brbr

网址:input type="text" name="website"

brbr

评论:textarea name="comment" rows="5" cols="40"/textarea

brbr

性别:

input type="radio" name="gender" value="female"女性

input type="radio" name="gender" value="male"男性

brbr

input type="submit" name="submit" value="提交"

/form

?php

echo "h2您的输入:/h2";

echo $name;

echo "br";

echo $email;

echo "br";

echo $website;

echo "br";

echo $comment;

echo "br";

echo $gender;

?

/body

/html


网站栏目:php提交查询数据 用php查询数据库信息
文章源于:http://myzitong.com/article/dooedcs.html