如何使用mysql

编程入门 行业动态 更新时间:2024-10-08 22:45:03
本文介绍了如何使用mysql_query()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

下面是用于从表中搜索用户输入值并打印它的php代码。 header.php

// html代码 < 表格 > < select name = 选择 > < 选项 value = empty > 无< / option > < 选项 value = 小说 > 小说< / option > < 选项 value = 期刊 > 期刊< / option > < 选项 value = acadamic > acadamic < / option > < /选择 > < form action = method = POST > < 输入 type = text value = 在此处输入关键字... 名称 = q size = 10 id = searchfield title = searchfield o nFocus = clearText(this) onBlur = clearText(this) / > < 输入 type = submit 名称 = 搜索 value = alt = 搜索 id = searchbutton title = 搜索 / > < / form > < / form > // php code <? php if (isset($ _ GET [' q '])&&a熔点; $ _GET [' q']!= ) { if($ _ GET [' select'] == fiction){ $ result = $ _ GET [' q']; // 存储用户输入的值 // echo $ a; $ sqlcommand = SELECT title,author FROM .USRBOOKS。 WHERE fiction ='$ result' ; }否则if($ _ GET [' select'] == journals){ $ result = $ _ GET [' q']; $ sqlcommand = SELECT title,author FROM .USRBOOKS。 WHERE fiction ='$ result'; } else if($ _ GET ['' select'] == acadamic){ $ result = $ _ GET [' q']; $ sqlcommand = SELECT title,author FROM .USRBOOKS。 WHERE fiction ='$ result'; } $ query = mysql_query($ sqlcommand)或 die($ sqlcommand); echo hello world; $ count = mysql_num_rows($ query); if ($ count> 0) { global $ searchoutput ; $ searchoutput = $ count results ; echo ' < META http-equiv =refreshcontent =0; URL =' .INDEX_URL。' result.php> '; // 尝试在新的php文件中打印结果 } } else { $ searchoutput = 0 result; echo ' < META http-equiv =refreshcontent =0; URL =' .INDEX_URL。' resultn.php> ; } ?>

当我试图搜索该值时,它正在打印选择查询。 如果我输入值xyz(假设它存在于虚构列的数据库表中) 而不是将资源存储到$ query(通过使用$ mysql_query)它打印低于值 SELECT title,author FROM books WHERE fiction = 'xyz' 请任何人解决我的问题

解决方案

_GET [' q'])&&

_GET [' q']!= ) { if(

_GET [' select'] == 小说){

below is the php code for searching user entered value from table and printing it. header.php

//html code <form> <select name="select"> <option value="empty">none</option> <option value="fiction">fiction</option> <option value="journals">journals</option> <option value="acadamic">acadamic</option> </select> <form action="" method="POST"> <input type="text" value="Enter a keyword here..." name="q" size="10" id="searchfield" title="searchfield" onFocus="clearText(this)" onBlur="clearText(this)" /> <input type="submit" name="Search" value="" alt="Search" id="searchbutton" title="Search" /> </form></form> // php code <?php if (isset($_GET['q']) && $_GET['q'] != "") { if($_GET['select'] == "fiction"){ $result=$_GET['q'];// storing user entered value //echo $a; $sqlcommand= "SELECT title,author FROM ".USRBOOKS." WHERE fiction = '$result'"; }else if($_GET['select'] == "journals"){ $result=$_GET['q']; $sqlcommand= "SELECT title,author FROM ".USRBOOKS." WHERE fiction = '$result'"; } else if($_GET['select'] == "acadamic"){ $result=$_GET['q']; $sqlcommand= "SELECT title,author FROM ".USRBOOKS." WHERE fiction = '$result'"; } $query = mysql_query($sqlcommand) or die($sqlcommand); echo "hello world"; $count = mysql_num_rows($query); if ($count>0) { global $searchoutput; $searchoutput = " $count results "; echo '<META http-equiv="refresh" content="0;URL='.INDEX_URL.'result.php">';// trying to print result in new php file } } else { $searchoutput="0 result"; echo '<META http-equiv="refresh" content="0;URL='.INDEX_URL.'resultn.php">'; } ?>

when ever I am trying to search the value, its is printing select query. if I entered value xyz (assume it is present in data base table in fiction column) instead of storing resource into $query (by using $mysql_query) it is printing below value SELECT title,author FROM books WHERE fiction = 'xyz' please anyone solve my problem

解决方案

_GET['q']) &&

_GET['q'] != "") { if(

_GET['select'] == "fiction"){

更多推荐

如何使用mysql

本文发布于:2023-06-02 01:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/431008.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!