Php connects to mysql to query a piece of data

Source: Internet
Author: User
Tags php mysql php mysql query
Php connects to mysql to query a Data Database. one table has a primary key pmcode and other attributes. I want to use pmcode to determine whether a user exists. If yes, retrieve the information, if it does not exist, "nonexistent" is returned, and then sent out by splicing xml. the code is as follows: // The member card number is obtained by splitting the sent information. & nbsp; & nbsp php connects to mysql to query a piece of data
A table in the database has a primary key pmcode and other attributes.
Now I want to use pmcode to determine whether a user exists. if the user exists, the user will retrieve the information. if the user does not exist, the user will return "nonexistent" and then send the information in xml format. the code is as follows:
// Obtain the membership card number for the information sent from the split.
$ Arry = explode ("+", $ form_Content );
$ Memberid = $ arry [1];

// Connect to the 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 );
// Query data
$ Result1 = mysql_query ("select * from numbers where pmcode = '". $ memberid ."';");

$ Num_result = mysql_num_rows ($ result1 );
If ($ num_result = 1 ){
// $ Row = $ result1-> fetch_assoc ();
$ Row = mysql_fetch_row ($ result1 );
$ Result_str = "your member -- information is as follows: \ n card number: $ row [pmcode]. \ n name :. $ row [names]. \ n level :. $ 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 = '". $ memberid ."'");
Echo $ resultStr;
Exit;

}

} Else {
Echo "failed to connect to database". mysql_error;
}
Mysql_close ($ link );
}

However, even if the correct pmcode is entered, the desired data cannot be obtained. please modify the php mysql Query and share it with us:
------ Solution --------------------
Oh, I made a mistake.
Echo $ row [1];

If there are garbled characters, add mysql_query ("set names utf8") to the query.
------ Solution --------------------
Change mysql_fetch_row to mysql_fetch_assoc... 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.