C# 在Xamarin中使用PHP/Mysql进行登录并重定向到另一个XAML
我刚开始使用Xamarin。现在我已经学会了如何创建跨平台应用程序。但现在我有一个担忧。我想从输入框中获取输入,如下所示 下面是我的XAML的外观:C# 在Xamarin中使用PHP/Mysql进行登录并重定向到另一个XAML,c#,php,mysql,authentication,xamarin,C#,Php,Mysql,Authentication,Xamarin,我刚开始使用Xamarin。现在我已经学会了如何创建跨平台应用程序。但现在我有一个担忧。我想从输入框中获取输入,如下所示 下面是我的XAML的外观: <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Qasimapp.Page1"
BackgroundColor="#fff">
<ContentPage.Content>
<StackLayout Spacing="20" Padding="50" VerticalOptions="Center">
<Image Source="slim_logo.png" x:Name="logom" HeightRequest="100" WidthRequest="100"/>
<Entry Placeholder="Username"></Entry>
<Entry Placeholder="Password" IsPassword="True"></Entry>
<Button Text="Log In" TextColor="White" BackgroundColor="#ff77D065"></Button>
</StackLayout>
</ContentPage.Content>
</ContentPage>
并使用它使用WebAPI或类似于普通PHP API的东西连接到数据库,然后重定向到另一个表单,如仪表板。下面是我的PHP的样子
<?php
require_once('inc/config.php');
$con = mysqli_connect($host,$user,$pass,$db) or die ('Cannot Connect to Database'.mysqli_error());
$username = mysqli_real_escape_string($con,$_POST['userID']);
$passwd = mysqli_real_escape_string($con,$_POST['passwd']);
$designation = mysqli_real_escape_string($con,$_POST['designation']);
$query = "SELECT * FROM evmsdbusers WHERE username='$username' AND password='$passwd' and designation='$designation'";
$result = mysqli_query($con,$query);
if (mysqli_num_rows($result) == 1) {
if($designation == 'User')
{
saveLoginLogs();
}
else if($designation =='Security')
{
saveLoginLogs();
}
}
?>
您应该首先创建一个restapi,请阅读关于在php中创建restapi的内容。然后你应该通过API将你的应用程序连接到你的后端。使用API连接你的应用程序和后端。阅读以了解如何使用RESTful Web服务。