我想使用 MySQL 和 php 在 windows phone 中创建登录过程。
下面是我的访问数据库代码,它不起作用。
XAML 代码
private void btnLogin_Click(System.Object sender, System.Windows.RoutedEventArgs e)
{
try
{
string url = "http://localhost/check_login/check.php";
//string url = "http://localhost/sam.php";
Uri uri = new Uri(url, UriKind.Absolute);
StringBuilder postData = new StringBuilder();
postData.AppendFormat("{0}={1}", "sUsername", HttpUtility.UrlEncode(this.txtUsername.Text));
postData.AppendFormat("&{0}={1}", "sPassword", HttpUtility.UrlEncode(this.txtPassword.Password.ToString()));
WebClient client = default(WebClient);
client = new WebClient();
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
client.Headers[HttpRequestHeader.ContentLength] = postData.Length.ToString();
client.UploadStringCompleted += client_UploadStringCompleted;
client.UploadProgressChanged += client_UploadProgressChanged;
client.UploadStringAsync(uri, "POST", postData.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
prog = new ProgressIndicator();
prog.IsIndeterminate = true;
prog.IsVisible = true;
prog.Text = "Loading....";
SystemTray.SetProgressIndicator(this, prog);
}
PHP代码
<?php
$objConnect = mysql_connect("localhost","root","");
$objDB = mysql_select_db("login_db");
//$_POST["sUsername"] = "weerachai"; // for Sample
//$_POST["sPassword"] = "weerachai@1"; // for Sample
$strUsername = $_POST["sUsername"];
$strPassword = $_POST["sPassword"];
$strSQL = "SELECT * FROM member WHERE 1
AND Username = '".$strUsername."'
AND Password = '".$strPassword."'
";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
$intNumRows = mysql_num_rows($objQuery);
if($intNumRows==0)
{
echo "0|0|Incorrect Username and Password";
}
else
{
echo "1|".$objResult["MemberID"]."|"."Valid User121";
}
/**
return
x|y|z
x // (0=Failed , 1=Complete)
y // MemberID
z // Error Message
*/
mysql_close($objConnect);
?>
我不知道添加任何其他内容以在模拟器中运行该文件。
请帮我。提前致谢。