我需要一些小帮助,因为我卡住了,我和PHP和vB.net连接不太好... 所以这里是问题,我设法连接到db和PHP脚本显示我,如果我连接或不,抓住如果用户/ pw是正确的一切正常,但现在我不知道如何抓住,在新表格上显示,来自该用户的数据并将其显示在标签中,例如在数据库中它有注册日期,上次登录和电子邮件,我想在我的第二个表单上获取它们...所以如果有人可以帮助我排序这些东西并设法完成目标,我真的很感激!
Usercheck.php
<?php
if($_POST)
{
if(isset($_POST["username"]) && isset($_POST["password"]))
{
$connect = mysql_pconnect("localhost","username","password");
if($connect)
{
$select = mysql_select_db("mydatabase",$connect);
if($select)
{
$user = mysql_escape_string($_POST["username"]);
$pwd = mysql_escape_string($_POST["password"]);
$GetRows = mysql_query("SELECT * FROM MyTableHere WHERE username='$user' AND password='$pwd'");
$RowCount=mysql_num_rows($GetRows);
if($RowCount>0)
{
die("Correct !");
}
else
{
die("Incorrect !");
}
}
else
{
die("Unable to select database." . mysql_error());
}
}
else
{
die("Unable connect to database." . mysql_error());
}
}
else
{
die("Access Denied!");
}
}
else
{
die("Access Denied!");
}
?>
Form1.vb的片段
Function AuthUser(ByVal AuthenticationPage As String, ByVal Username As String, ByVal Password As String) As Boolean
Dim wc As New WebClient()
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
Dim Data As String = String.Format("username={0}&password={1}", HttpUtility.UrlEncode(Username), HttpUtility.UrlEncode(Password))
Dim ResponseBytes() As Byte = wc.UploadData(AuthenticationPage, "POST", Encoding.ASCII.GetBytes(Data))
Dim Response As String = Encoding.ASCII.GetString(ResponseBytes)
If Response.Contains("Correct") Then
Return True
Else
Return False
End If
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If AuthUser("http://127.0.0.1/Usercheck.php", TextBox1.Text, TextBox2.Text) Then
Me.Hide()
Form2.Show()
Else
MsgBox("You have provided invalid username or password. Unable to login.")
End If
End Sub
答案 0 :(得分:0)
这可能会有所帮助 http://www.aspfree.com/c/a/vb-net/bridging-the-gap-talking-to-mysql-from-vb-net-through-php-and-xml/
它显示了如何通过php生成的mysql显示来自mysql的数据。
答案 1 :(得分:0)
尝试在vb.net中将值声明为全局变量。然后,您可以在整个项目中访问所述变量,甚至可以以其他形式访问该变量。