PHP joins MySQL query for a single piece of data

Source: Internet
Author: User
Tags mysql query
PHP connection MySQL Query a piece of data
There is a table in the database with a primary key Pmcode and other properties
I now want to determine whether a user exists by Pmcode, if there is a message out of it, does not exist return "does not exist", and then through the form of splicing XML sent out, the code is as follows:
Split the distribution of information to get the membership card number
$arry =explode ("+", $form _content);
$memberid = $arry [1];

Connecting to a database
$link =mysql_connect (sae_mysql_host_m. ': '). Sae_mysql_port,sae_mysql_user,sae_mysql_pass);
if ($link) {
mysql_select_db (sae_mysql_db, $link);
Querying data
$result 1=mysql_query ("select * from numbers where Pmcode = '". $memberid. "';");

$num _result = mysql_num_rows ($result 1);
if ($num _result==1) {
$row = $result 1->fetch_assoc ();
$row =mysql_fetch_row ($result 1);
$result _str= "Your member-information is as follows: \ n/A card number: $row [pmcode].\n name:. $row [names].\n Rating:. $row [4].\n points: $a [5]";
$RESULTSTR = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, $result _str);
Echo $resultStr;
Exit
}else{
$msgType = "text";
$RESULTSTR = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, "--select * from numbers where Pmcode = '". $mem Berid. "'");
Echo $resultStr;
Exit

}

} else{
echo "Failed to connect to database". Mysql_error;
}
Mysql_close ($link);
}

But even if the right pmcode are not marrying the data they want, ask God to modify it. PHP MySQL Enquiry

Share to:


------Solution--------------------
Oh, I got it wrong.
echo $row [1];

There is garbled, query front plus a sentence: mysql_query ("Set names UTF8"); Give it a try
------Solution--------------------
You change mysql_fetch_row to Mysql_fetch_assoc and try ... And then print the array
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.