请教CSDN的老师帮忙解决个问题PHP查询的问题?菜鸟咨询!本人使用 phpcms 2008  做个个小站点!虚拟服务器 环境是 PHP+mysql 我仅懂一点HTML 制作简单的模板  现在需要个PHP 查询的问题我创建了一个数据表   phpcms_product
                                pid        pname     pdescription
                                123        coth         good coth
                                345        foot         good  foot 
                                324       ddd          abcdefg
上面的表格   通过 PHPCMS 自建字段就可以解决了  内容 也可以添加  
下面是我的网页代码  请老师们帮写 查询代码:要求 按 pid的值查询,如果输入 123  显示  
123
coth
good coth
输入 输入   456(pid 值的列表中 没有这个值)那么  显示没有该编号的相关信息多谢了 
<script language=javascript> 
<!--
function check(){
 if (chaxun.zkzh.value==""){
 alert("请输入你的产品代码!"); return false;
 }
 var filter=/^\s*[.A-Za-z0-9_-]{6,20}\s*$/;
 if (!filter.test(chaxun.zkzh.value)) 
 { 
  alert("你的产品代码填写不正确,请重新填写!"); 
 
   return false; 
 }  
  if (chaxun.checkcode.value==""){
 alert("请输入随机验证码!"); return false;
 }
return True;
}
//-->
</script><table width="770" height="295" border="0" align="center" cellpadding="0" cellspacing="0" background:#666666; >
        <!--DWLayoutTable-->
        <tr>
          <td width="777" height="200"><table width="406" border="0" align="center">
            <form  method="post" name="chaxun" action="search.asp" target="_blank" onSubmit="return check();">
            <tr>
              <td width="90"><div align="right">产品代码:</div></td>
              <td width="306"><div align="left">
                <input name="zkzh" type="text" class=input size="20" onMouseOver ="this.style.backgroundColor='#ffffff'" onMouseOut ="this.style.backgroundColor='#f0ffff'">
              </div></td>
            </tr>
            <tr>
              <td><div align="right">随机验证:</div></td>
              <td><div align="left">
                <input name="checkcode"  class=input type="text" size="4" maxlength="4" onMouseOver ="this.style.backgroundColor='#ffffff'" onMouseOut ="this.style.backgroundColor='#f0ffff'">
              <img src="checkcode.asp" style='cursor:hand;width:40px;height:14px' border='0' align='absmiddle' onclick="this.src='checkcode.php'" alt='请点击刷新验证码' /> ←请点击刷新验证码</div></td>
            </tr>
            <tr>
              <td><br/></td>
              <td><div align="left">
                <input type="submit" name="submit" value="查询产品信息" class="button" onmouseover ="this.style.backgroundColor='#FFF1DF'" onmouseout ="this.style.backgroundColor='#DDFAFF'" />
              </div></td>
            </tr></form>
          </table></td>
  </tr>
    
</table>

解决方案 »

  1.   

    search.asp<?php 
    /* 连接数据库的代码自己补上 */
    $zkzh = $_POST['zkzh'];
    $query = mysql_query('select * from phpcms_product where pid='.$id)
    $row = mysql_fetch_array($query);
    if (is_array($row))
    {
        echo $row['pid'] . '<br>';
    echo $row['pname'] . '<br>';
    echo $row['pdescription'] . '<br>';
    }
    else
    {
    echo '没有该编号的相关信息';
    }
    ?>
      

  2.   

    checkcode.php
    <?php 
    mysql_connect("localhost ", "admin ", "admin ") //填写mysql用户名和密码       
       or die("Could not connect to MySQL server!");       
    mysql_select_db("phpcms") //数据库名       
       or die("Could not select database!");       
    mysql_query('set names "gbk_chinese_ci"'); //数据库内数据的编码     $zkzh = $_POST['zkzh'];
    $query = mysql_query('select * from phpcms_productsn where pid='.$id)
    $row = mysql_fetch_array($query);
    if (is_array($row))
    {
        echo $row['pid'] . '<br>';
        echo $row['pname'] . '<br>';
        echo $row['pdescription'] . '<br>';
    }
    else
    {
        echo '没有该编号的相关信息';
    }?>
    index.html
    <script language=javascript>  
    <!--
    function check(){
     if (chaxun.zkzh.value==""){
     alert("请输入你的产品代码!"); return false;
     }
     var filter=/^\s*[.A-Za-z0-9_-]{6,20}\s*$/;
     if (!filter.test(chaxun.zkzh.value))  
     {  
      alert("你的产品代码填写不正确,请重新填写!");  
     
      return false;  
     }   return True;
    }
    //-->
    </script>
    <form method="post" name="chaxun" action="checkcode.php" target="_blank" onSubmit="return check();">
     <form method="post" name="chaxun" action="checkcode.php" target="_blank" onSubmit="return check();">
     产品代码: <input name="zkzh" type="text" class=input size="20"><br/>
       <input type="submit" name="submit" value="查询产品信息" class="button"/>
    </form>数据库 情况是
    CREATE TABLE `phpcms`.`phpcms_productsn` (
    `pid` INT( 13 ) UNSIGNED NOT NULL ,
    `pname` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE gbk_chinese_ci NOT NULL ,
    `pdescription` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE gbk_chinese_ci NOT NULL 
    ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE gbk_chinese_ci;请问 那里不对了  老是报错!
    Parse error: syntax error, unexpected T_VARIABLE in D:\PC_webserver\phproot\checkcode\checkcode.php on line 11
      

  3.   

    $zkzh = $_POST['zkzh'];
    $query = mysql_query('select * from phpcms_productsn where pid='.$zkzh);
    少了个分号 每一行结束都要有个分号
      

  4.   


    mysql_connect("localhost ", "admin ", "admin ") //填写mysql用户名和密码   
      or die("Could not connect to MySQL server!");   
    mysql_select_db("phpcms") //数据库名   
      or die("Could not select database!");   
    mysql_query('set names "gbk_chinese_ci"'); //数据库内数据的编码  这断代码也错  不到服务器我的用户名 和密码 都是 admin
    数据库名称 是   phpcms
    对应的数据表 是 phpcms_productsn
      

  5.   

    $conn = mysql_connect("localhost","admin","admin") or die("Could not connect to MySQL server!");
    mysql_select_db("phpcms",$conn);
    mysql_query("set names gbk");
      

  6.   

    输入一个 不存在的编码  
    显示结果如下:Notice: Undefined variable: id in D:\PC_webserver\phproot\checkcode\checkcode.php on line 7Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\PC_webserver\phproot\checkcode\checkcode.php on line 8
    没有该编号的相关信息对应的
    line 7
    $query = mysql_query('select * from phpcms_pmsn where pid='.$id);line 8
    $row = mysql_fetch_array($query);
      

  7.   

    数据库名字 被我改成 pmsn
      

  8.   

    上面的id是我写错 
    $zkzh = $_POST['zkzh']; //$zkzhp 这个变量名你可以自己命名 $_POST['zkzh']这里的zkzh要跟你表单中的一样
    $query = mysql_query('select * from phpcms_productsn where pid='.$zkzh);  //你上面用那个变量名这里要一样