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