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