Home >Backend Development >PHP Tutorial > php联接mysql查询一条数据

php联接mysql查询一条数据

WBOY
WBOYOriginal
2016-06-13 12:36:491294browse

php连接mysql查询一条数据
数据库中有张表有主键pmcode还有其他属性如图:
我现在想通过pmcode判断某个用户是否存在,存在的话将其信息取出,不存在的话返回"不存在",然后通过拼接xml的形式发送出去,代码如下:

//拆分发来的信息得到会员卡号<br />
            $arry=explode("+",$form_Content);<br />
            $memberid =$arry[1];<br />
<br />
              //连接数据库<br />
            $link=mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS);<br />
               if($link) {<br />
                   mysql_select_db(SAE_MYSQL_DB,$link); <br />
                   //查询数据<br />
                   $result1=mysql_query("select * from numbers where pmcode = '".$memberid."';");<br />
<br />
                 $num_result = mysql_num_rows($result1);<br />
                   if($num_result==1){<br />
                       //   $row= $result1->fetch_assoc();<br />
                       $row=mysql_fetch_row($result1);<br />
                        $result_str="您的会员--信息如下:\n\n卡号:$row[pmcode].\n姓名:.$row[names].\n等级:.$row[4].\n积分:$a[5]";<br />
                         $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType,$result_str); <br />
                        echo $resultStr;                  <br />
                         exit;<br />
                   }else{<br />
                     $msgType = "text";<br />
                    $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType,"--select * from numbers where pmcode = '".$memberid."'");  <br />
                    echo $resultStr;                  <br />
                    exit;<br />
<br />
                   }<br />
<br />
        }   else{<br />
             echo "连接数据库失败".mysql_error;<br />
            }            <br />
               mysql_close($link);<br />
        }

可是就算输入正确的pmcode都娶不到想要的数据,求大神修改

php mysql 查询
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn