I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP












0














    <?php
$servername = "localhost";
$username="root";
$password="";
$dbName="escape_room";
$user_username = $_POST['Input_user'];
$user_password = $_POST['Input_pass'];
$conn = new mysqli($servername, $username, $password, $dbName);
if(!$conn){
die("Cound not Connect: " . mysqli_connect_error());
}

$sql = "SELECT pass FROM escape_room WHERE user = '".$user_username."' ";
$result = mysqli_query($conn, $sql);

//Get the result and confirm login
if(mysqli_num_rows($result)>0){
while($row = mysqli_fetch_assoc($result)){
if($row['pass'] == $user_password){
echo "login success";
echo $row['pass'];
}else{
echo "password incorrect";
echo "password is =". $row['pass'];
}
}
}else{
echo "user not found";
echo "password is =". $row['pass'];}


I created a WWWForm in Unity C Script and tried to get the value of Mysqlitedatabase by running Login.php on server XAMPP. However, I could not confirm whether the IDs match or not. Only code written in html language will appear in console.



    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Object not found!</title>
...


What should I do?
Thank you for reading.



using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class gamemanager : MonoBehaviour {

[Header("LoginPanel")]
public InputField ID;
public InputField PW;
[Header("CreateAccountPanel")]
public InputField New_ID;
public InputField New_PW;

public string LoginUrI;
// Use this for initialization
void Start () {
LoginUrI = "localhost/escape_room/Login.php";
}


public void LoginBtn()
{
StartCoroutine(LoginToDB(ID, PW));
}

IEnumerator LoginToDB(InputField username, InputField password)
{
Debug.Log(username.text);
Debug.Log(password.text);

WWWForm form = new WWWForm();
form.AddField("Input_user", username.text);
form.AddField("Input_pass", password.text);

WWW webRequest = new WWW(LoginUrI, form);

yield return webRequest;
Debug.Log(webRequest.text);

}

public void CreateAccountBtn()
{

}
}


+Add)
[ This is what I have implemented in the Unity C script. I have an InputField and I used an AddField method to accept that inputField and pass it to php. In addition, I created a WWW object to allow access to Login.php through the server. At the end, I tested via Debug.Log to see how well the logged-in results would look good. ]










share|improve this question
























  • PHP file containing the code is not found by the server. You might be executing wrong url or file.
    – Milind Singh
    Nov 21 at 4:47










  • You should really consult a tutorial before proceeding with this project. User input direct to SQL is a red flag, as is plain text passwords. Also why iterate over the result set, isn't there only 1 user per username? If not that is a security problem as well because username john could be two people.
    – user3783243
    Nov 21 at 4:50












  • @user3783243 It has helped a lot. I've changed the code, can this be a better code? $numrows = mysql_num_rows($check); if ($numrows == 0) { die("ID does not exist. n"); }
    – 황인규
    Nov 21 at 5:01












  • You can't use mysql_ functions with mysqli. Use mysqli everywhere, you're going backwards many years if you go to mysql_
    – user3783243
    Nov 21 at 5:04












  • @MilindSingh In Unity I declare LoginUrI = 'localhost / escape_room / Login.php' as follows: Is this URL wrong?
    – 황인규
    Nov 21 at 5:05
















0














    <?php
$servername = "localhost";
$username="root";
$password="";
$dbName="escape_room";
$user_username = $_POST['Input_user'];
$user_password = $_POST['Input_pass'];
$conn = new mysqli($servername, $username, $password, $dbName);
if(!$conn){
die("Cound not Connect: " . mysqli_connect_error());
}

$sql = "SELECT pass FROM escape_room WHERE user = '".$user_username."' ";
$result = mysqli_query($conn, $sql);

//Get the result and confirm login
if(mysqli_num_rows($result)>0){
while($row = mysqli_fetch_assoc($result)){
if($row['pass'] == $user_password){
echo "login success";
echo $row['pass'];
}else{
echo "password incorrect";
echo "password is =". $row['pass'];
}
}
}else{
echo "user not found";
echo "password is =". $row['pass'];}


I created a WWWForm in Unity C Script and tried to get the value of Mysqlitedatabase by running Login.php on server XAMPP. However, I could not confirm whether the IDs match or not. Only code written in html language will appear in console.



    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Object not found!</title>
...


What should I do?
Thank you for reading.



using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class gamemanager : MonoBehaviour {

[Header("LoginPanel")]
public InputField ID;
public InputField PW;
[Header("CreateAccountPanel")]
public InputField New_ID;
public InputField New_PW;

public string LoginUrI;
// Use this for initialization
void Start () {
LoginUrI = "localhost/escape_room/Login.php";
}


public void LoginBtn()
{
StartCoroutine(LoginToDB(ID, PW));
}

IEnumerator LoginToDB(InputField username, InputField password)
{
Debug.Log(username.text);
Debug.Log(password.text);

WWWForm form = new WWWForm();
form.AddField("Input_user", username.text);
form.AddField("Input_pass", password.text);

WWW webRequest = new WWW(LoginUrI, form);

yield return webRequest;
Debug.Log(webRequest.text);

}

public void CreateAccountBtn()
{

}
}


+Add)
[ This is what I have implemented in the Unity C script. I have an InputField and I used an AddField method to accept that inputField and pass it to php. In addition, I created a WWW object to allow access to Login.php through the server. At the end, I tested via Debug.Log to see how well the logged-in results would look good. ]










share|improve this question
























  • PHP file containing the code is not found by the server. You might be executing wrong url or file.
    – Milind Singh
    Nov 21 at 4:47










  • You should really consult a tutorial before proceeding with this project. User input direct to SQL is a red flag, as is plain text passwords. Also why iterate over the result set, isn't there only 1 user per username? If not that is a security problem as well because username john could be two people.
    – user3783243
    Nov 21 at 4:50












  • @user3783243 It has helped a lot. I've changed the code, can this be a better code? $numrows = mysql_num_rows($check); if ($numrows == 0) { die("ID does not exist. n"); }
    – 황인규
    Nov 21 at 5:01












  • You can't use mysql_ functions with mysqli. Use mysqli everywhere, you're going backwards many years if you go to mysql_
    – user3783243
    Nov 21 at 5:04












  • @MilindSingh In Unity I declare LoginUrI = 'localhost / escape_room / Login.php' as follows: Is this URL wrong?
    – 황인규
    Nov 21 at 5:05














0












0








0







    <?php
$servername = "localhost";
$username="root";
$password="";
$dbName="escape_room";
$user_username = $_POST['Input_user'];
$user_password = $_POST['Input_pass'];
$conn = new mysqli($servername, $username, $password, $dbName);
if(!$conn){
die("Cound not Connect: " . mysqli_connect_error());
}

$sql = "SELECT pass FROM escape_room WHERE user = '".$user_username."' ";
$result = mysqli_query($conn, $sql);

//Get the result and confirm login
if(mysqli_num_rows($result)>0){
while($row = mysqli_fetch_assoc($result)){
if($row['pass'] == $user_password){
echo "login success";
echo $row['pass'];
}else{
echo "password incorrect";
echo "password is =". $row['pass'];
}
}
}else{
echo "user not found";
echo "password is =". $row['pass'];}


I created a WWWForm in Unity C Script and tried to get the value of Mysqlitedatabase by running Login.php on server XAMPP. However, I could not confirm whether the IDs match or not. Only code written in html language will appear in console.



    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Object not found!</title>
...


What should I do?
Thank you for reading.



using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class gamemanager : MonoBehaviour {

[Header("LoginPanel")]
public InputField ID;
public InputField PW;
[Header("CreateAccountPanel")]
public InputField New_ID;
public InputField New_PW;

public string LoginUrI;
// Use this for initialization
void Start () {
LoginUrI = "localhost/escape_room/Login.php";
}


public void LoginBtn()
{
StartCoroutine(LoginToDB(ID, PW));
}

IEnumerator LoginToDB(InputField username, InputField password)
{
Debug.Log(username.text);
Debug.Log(password.text);

WWWForm form = new WWWForm();
form.AddField("Input_user", username.text);
form.AddField("Input_pass", password.text);

WWW webRequest = new WWW(LoginUrI, form);

yield return webRequest;
Debug.Log(webRequest.text);

}

public void CreateAccountBtn()
{

}
}


+Add)
[ This is what I have implemented in the Unity C script. I have an InputField and I used an AddField method to accept that inputField and pass it to php. In addition, I created a WWW object to allow access to Login.php through the server. At the end, I tested via Debug.Log to see how well the logged-in results would look good. ]










share|improve this question















    <?php
$servername = "localhost";
$username="root";
$password="";
$dbName="escape_room";
$user_username = $_POST['Input_user'];
$user_password = $_POST['Input_pass'];
$conn = new mysqli($servername, $username, $password, $dbName);
if(!$conn){
die("Cound not Connect: " . mysqli_connect_error());
}

$sql = "SELECT pass FROM escape_room WHERE user = '".$user_username."' ";
$result = mysqli_query($conn, $sql);

//Get the result and confirm login
if(mysqli_num_rows($result)>0){
while($row = mysqli_fetch_assoc($result)){
if($row['pass'] == $user_password){
echo "login success";
echo $row['pass'];
}else{
echo "password incorrect";
echo "password is =". $row['pass'];
}
}
}else{
echo "user not found";
echo "password is =". $row['pass'];}


I created a WWWForm in Unity C Script and tried to get the value of Mysqlitedatabase by running Login.php on server XAMPP. However, I could not confirm whether the IDs match or not. Only code written in html language will appear in console.



    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Object not found!</title>
...


What should I do?
Thank you for reading.



using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class gamemanager : MonoBehaviour {

[Header("LoginPanel")]
public InputField ID;
public InputField PW;
[Header("CreateAccountPanel")]
public InputField New_ID;
public InputField New_PW;

public string LoginUrI;
// Use this for initialization
void Start () {
LoginUrI = "localhost/escape_room/Login.php";
}


public void LoginBtn()
{
StartCoroutine(LoginToDB(ID, PW));
}

IEnumerator LoginToDB(InputField username, InputField password)
{
Debug.Log(username.text);
Debug.Log(password.text);

WWWForm form = new WWWForm();
form.AddField("Input_user", username.text);
form.AddField("Input_pass", password.text);

WWW webRequest = new WWW(LoginUrI, form);

yield return webRequest;
Debug.Log(webRequest.text);

}

public void CreateAccountBtn()
{

}
}


+Add)
[ This is what I have implemented in the Unity C script. I have an InputField and I used an AddField method to accept that inputField and pass it to php. In addition, I created a WWW object to allow access to Login.php through the server. At the end, I tested via Debug.Log to see how well the logged-in results would look good. ]







php sqlite unity3d login xampp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 6:09

























asked Nov 21 at 4:43









황인규

255




255












  • PHP file containing the code is not found by the server. You might be executing wrong url or file.
    – Milind Singh
    Nov 21 at 4:47










  • You should really consult a tutorial before proceeding with this project. User input direct to SQL is a red flag, as is plain text passwords. Also why iterate over the result set, isn't there only 1 user per username? If not that is a security problem as well because username john could be two people.
    – user3783243
    Nov 21 at 4:50












  • @user3783243 It has helped a lot. I've changed the code, can this be a better code? $numrows = mysql_num_rows($check); if ($numrows == 0) { die("ID does not exist. n"); }
    – 황인규
    Nov 21 at 5:01












  • You can't use mysql_ functions with mysqli. Use mysqli everywhere, you're going backwards many years if you go to mysql_
    – user3783243
    Nov 21 at 5:04












  • @MilindSingh In Unity I declare LoginUrI = 'localhost / escape_room / Login.php' as follows: Is this URL wrong?
    – 황인규
    Nov 21 at 5:05


















  • PHP file containing the code is not found by the server. You might be executing wrong url or file.
    – Milind Singh
    Nov 21 at 4:47










  • You should really consult a tutorial before proceeding with this project. User input direct to SQL is a red flag, as is plain text passwords. Also why iterate over the result set, isn't there only 1 user per username? If not that is a security problem as well because username john could be two people.
    – user3783243
    Nov 21 at 4:50












  • @user3783243 It has helped a lot. I've changed the code, can this be a better code? $numrows = mysql_num_rows($check); if ($numrows == 0) { die("ID does not exist. n"); }
    – 황인규
    Nov 21 at 5:01












  • You can't use mysql_ functions with mysqli. Use mysqli everywhere, you're going backwards many years if you go to mysql_
    – user3783243
    Nov 21 at 5:04












  • @MilindSingh In Unity I declare LoginUrI = 'localhost / escape_room / Login.php' as follows: Is this URL wrong?
    – 황인규
    Nov 21 at 5:05
















PHP file containing the code is not found by the server. You might be executing wrong url or file.
– Milind Singh
Nov 21 at 4:47




PHP file containing the code is not found by the server. You might be executing wrong url or file.
– Milind Singh
Nov 21 at 4:47












You should really consult a tutorial before proceeding with this project. User input direct to SQL is a red flag, as is plain text passwords. Also why iterate over the result set, isn't there only 1 user per username? If not that is a security problem as well because username john could be two people.
– user3783243
Nov 21 at 4:50






You should really consult a tutorial before proceeding with this project. User input direct to SQL is a red flag, as is plain text passwords. Also why iterate over the result set, isn't there only 1 user per username? If not that is a security problem as well because username john could be two people.
– user3783243
Nov 21 at 4:50














@user3783243 It has helped a lot. I've changed the code, can this be a better code? $numrows = mysql_num_rows($check); if ($numrows == 0) { die("ID does not exist. n"); }
– 황인규
Nov 21 at 5:01






@user3783243 It has helped a lot. I've changed the code, can this be a better code? $numrows = mysql_num_rows($check); if ($numrows == 0) { die("ID does not exist. n"); }
– 황인규
Nov 21 at 5:01














You can't use mysql_ functions with mysqli. Use mysqli everywhere, you're going backwards many years if you go to mysql_
– user3783243
Nov 21 at 5:04






You can't use mysql_ functions with mysqli. Use mysqli everywhere, you're going backwards many years if you go to mysql_
– user3783243
Nov 21 at 5:04














@MilindSingh In Unity I declare LoginUrI = 'localhost / escape_room / Login.php' as follows: Is this URL wrong?
– 황인규
Nov 21 at 5:05




@MilindSingh In Unity I declare LoginUrI = 'localhost / escape_room / Login.php' as follows: Is this URL wrong?
– 황인규
Nov 21 at 5:05












1 Answer
1






active

oldest

votes


















0















  1. confirm your path on xampp, to be sure that this is your directory path C:xampphtdocsescape_roomLogin.php

  2. You need to actually post the form from unity first, see code below

  3. Debug the php alone without sql to make sure you're getting the correct data. see code.


WWWform



    using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using UnityEngine.Networking;
public class gamemanager : MonoBehaviour {

[Header("LoginPanel")]
public InputField ID;
public InputField PW;
[Header("CreateAccountPanel")]
public InputField New_ID;
public InputField New_PW;

string LoginUrI = "http://localhost/escape_room/login.php";
// Use this for initialization
void Start () {

}


public void LoginBtn()
{
StartCoroutine(LoginToDB(ID, PW));
}

IEnumerator LoginToDB(InputField username, InputField password)
{
Debug.Log(username.text);
Debug.Log(password.text);

WWWForm form = new WWWForm();
form.AddField("Input_user", username.text);
form.AddField("Input_pass", password.text);

// Make Post Request
using (var w = UnityWebRequest.Post(LoginUrI, form))
{
yield return w.SendWebRequest();
if (w.isNetworkError || w.isHttpError) {
Debug.Log(w.error);
}
else {
Debug.Log(w.downloadHandler.text);
}
}


}

public void CreateAccountBtn()
{

}
}


Test php code, replace you Login.php with this to make sure you get the values first.



<?php


if(isset($_POST) && !empty($_POST)){
echo "Successful post";
var_dump($_POST);
} else die("Error: post not successful");
?>





share|improve this answer























  • Generic / unknown HTTP error. I am using xampp's server, MySql, and I don't know why I get an error.
    – 황인규
    Nov 21 at 7:24










  • I use both too, not sure why, does it work for other things?
    – comphonia
    Nov 21 at 7:27










  • No. I only ran it on my laptop.
    – 황인규
    Nov 21 at 7:35












  • copy the new C# code, just tested it in unity and its working. the public string was messing it up, I also set it outside of Start()
    – comphonia
    Nov 21 at 7:41










  • you should see the results as a unity debug, without having to go to the browser, so you know its posted
    – comphonia
    Nov 21 at 7:45











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405384%2fi-get-strange-results-when-i-access-the-sqlitedatabase-with-unity-c-sharp-via-xa%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0















  1. confirm your path on xampp, to be sure that this is your directory path C:xampphtdocsescape_roomLogin.php

  2. You need to actually post the form from unity first, see code below

  3. Debug the php alone without sql to make sure you're getting the correct data. see code.


WWWform



    using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using UnityEngine.Networking;
public class gamemanager : MonoBehaviour {

[Header("LoginPanel")]
public InputField ID;
public InputField PW;
[Header("CreateAccountPanel")]
public InputField New_ID;
public InputField New_PW;

string LoginUrI = "http://localhost/escape_room/login.php";
// Use this for initialization
void Start () {

}


public void LoginBtn()
{
StartCoroutine(LoginToDB(ID, PW));
}

IEnumerator LoginToDB(InputField username, InputField password)
{
Debug.Log(username.text);
Debug.Log(password.text);

WWWForm form = new WWWForm();
form.AddField("Input_user", username.text);
form.AddField("Input_pass", password.text);

// Make Post Request
using (var w = UnityWebRequest.Post(LoginUrI, form))
{
yield return w.SendWebRequest();
if (w.isNetworkError || w.isHttpError) {
Debug.Log(w.error);
}
else {
Debug.Log(w.downloadHandler.text);
}
}


}

public void CreateAccountBtn()
{

}
}


Test php code, replace you Login.php with this to make sure you get the values first.



<?php


if(isset($_POST) && !empty($_POST)){
echo "Successful post";
var_dump($_POST);
} else die("Error: post not successful");
?>





share|improve this answer























  • Generic / unknown HTTP error. I am using xampp's server, MySql, and I don't know why I get an error.
    – 황인규
    Nov 21 at 7:24










  • I use both too, not sure why, does it work for other things?
    – comphonia
    Nov 21 at 7:27










  • No. I only ran it on my laptop.
    – 황인규
    Nov 21 at 7:35












  • copy the new C# code, just tested it in unity and its working. the public string was messing it up, I also set it outside of Start()
    – comphonia
    Nov 21 at 7:41










  • you should see the results as a unity debug, without having to go to the browser, so you know its posted
    – comphonia
    Nov 21 at 7:45
















0















  1. confirm your path on xampp, to be sure that this is your directory path C:xampphtdocsescape_roomLogin.php

  2. You need to actually post the form from unity first, see code below

  3. Debug the php alone without sql to make sure you're getting the correct data. see code.


WWWform



    using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using UnityEngine.Networking;
public class gamemanager : MonoBehaviour {

[Header("LoginPanel")]
public InputField ID;
public InputField PW;
[Header("CreateAccountPanel")]
public InputField New_ID;
public InputField New_PW;

string LoginUrI = "http://localhost/escape_room/login.php";
// Use this for initialization
void Start () {

}


public void LoginBtn()
{
StartCoroutine(LoginToDB(ID, PW));
}

IEnumerator LoginToDB(InputField username, InputField password)
{
Debug.Log(username.text);
Debug.Log(password.text);

WWWForm form = new WWWForm();
form.AddField("Input_user", username.text);
form.AddField("Input_pass", password.text);

// Make Post Request
using (var w = UnityWebRequest.Post(LoginUrI, form))
{
yield return w.SendWebRequest();
if (w.isNetworkError || w.isHttpError) {
Debug.Log(w.error);
}
else {
Debug.Log(w.downloadHandler.text);
}
}


}

public void CreateAccountBtn()
{

}
}


Test php code, replace you Login.php with this to make sure you get the values first.



<?php


if(isset($_POST) && !empty($_POST)){
echo "Successful post";
var_dump($_POST);
} else die("Error: post not successful");
?>





share|improve this answer























  • Generic / unknown HTTP error. I am using xampp's server, MySql, and I don't know why I get an error.
    – 황인규
    Nov 21 at 7:24










  • I use both too, not sure why, does it work for other things?
    – comphonia
    Nov 21 at 7:27










  • No. I only ran it on my laptop.
    – 황인규
    Nov 21 at 7:35












  • copy the new C# code, just tested it in unity and its working. the public string was messing it up, I also set it outside of Start()
    – comphonia
    Nov 21 at 7:41










  • you should see the results as a unity debug, without having to go to the browser, so you know its posted
    – comphonia
    Nov 21 at 7:45














0












0








0







  1. confirm your path on xampp, to be sure that this is your directory path C:xampphtdocsescape_roomLogin.php

  2. You need to actually post the form from unity first, see code below

  3. Debug the php alone without sql to make sure you're getting the correct data. see code.


WWWform



    using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using UnityEngine.Networking;
public class gamemanager : MonoBehaviour {

[Header("LoginPanel")]
public InputField ID;
public InputField PW;
[Header("CreateAccountPanel")]
public InputField New_ID;
public InputField New_PW;

string LoginUrI = "http://localhost/escape_room/login.php";
// Use this for initialization
void Start () {

}


public void LoginBtn()
{
StartCoroutine(LoginToDB(ID, PW));
}

IEnumerator LoginToDB(InputField username, InputField password)
{
Debug.Log(username.text);
Debug.Log(password.text);

WWWForm form = new WWWForm();
form.AddField("Input_user", username.text);
form.AddField("Input_pass", password.text);

// Make Post Request
using (var w = UnityWebRequest.Post(LoginUrI, form))
{
yield return w.SendWebRequest();
if (w.isNetworkError || w.isHttpError) {
Debug.Log(w.error);
}
else {
Debug.Log(w.downloadHandler.text);
}
}


}

public void CreateAccountBtn()
{

}
}


Test php code, replace you Login.php with this to make sure you get the values first.



<?php


if(isset($_POST) && !empty($_POST)){
echo "Successful post";
var_dump($_POST);
} else die("Error: post not successful");
?>





share|improve this answer















  1. confirm your path on xampp, to be sure that this is your directory path C:xampphtdocsescape_roomLogin.php

  2. You need to actually post the form from unity first, see code below

  3. Debug the php alone without sql to make sure you're getting the correct data. see code.


WWWform



    using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using UnityEngine.Networking;
public class gamemanager : MonoBehaviour {

[Header("LoginPanel")]
public InputField ID;
public InputField PW;
[Header("CreateAccountPanel")]
public InputField New_ID;
public InputField New_PW;

string LoginUrI = "http://localhost/escape_room/login.php";
// Use this for initialization
void Start () {

}


public void LoginBtn()
{
StartCoroutine(LoginToDB(ID, PW));
}

IEnumerator LoginToDB(InputField username, InputField password)
{
Debug.Log(username.text);
Debug.Log(password.text);

WWWForm form = new WWWForm();
form.AddField("Input_user", username.text);
form.AddField("Input_pass", password.text);

// Make Post Request
using (var w = UnityWebRequest.Post(LoginUrI, form))
{
yield return w.SendWebRequest();
if (w.isNetworkError || w.isHttpError) {
Debug.Log(w.error);
}
else {
Debug.Log(w.downloadHandler.text);
}
}


}

public void CreateAccountBtn()
{

}
}


Test php code, replace you Login.php with this to make sure you get the values first.



<?php


if(isset($_POST) && !empty($_POST)){
echo "Successful post";
var_dump($_POST);
} else die("Error: post not successful");
?>






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 at 7:40

























answered Nov 21 at 6:53









comphonia

42828




42828












  • Generic / unknown HTTP error. I am using xampp's server, MySql, and I don't know why I get an error.
    – 황인규
    Nov 21 at 7:24










  • I use both too, not sure why, does it work for other things?
    – comphonia
    Nov 21 at 7:27










  • No. I only ran it on my laptop.
    – 황인규
    Nov 21 at 7:35












  • copy the new C# code, just tested it in unity and its working. the public string was messing it up, I also set it outside of Start()
    – comphonia
    Nov 21 at 7:41










  • you should see the results as a unity debug, without having to go to the browser, so you know its posted
    – comphonia
    Nov 21 at 7:45


















  • Generic / unknown HTTP error. I am using xampp's server, MySql, and I don't know why I get an error.
    – 황인규
    Nov 21 at 7:24










  • I use both too, not sure why, does it work for other things?
    – comphonia
    Nov 21 at 7:27










  • No. I only ran it on my laptop.
    – 황인규
    Nov 21 at 7:35












  • copy the new C# code, just tested it in unity and its working. the public string was messing it up, I also set it outside of Start()
    – comphonia
    Nov 21 at 7:41










  • you should see the results as a unity debug, without having to go to the browser, so you know its posted
    – comphonia
    Nov 21 at 7:45
















Generic / unknown HTTP error. I am using xampp's server, MySql, and I don't know why I get an error.
– 황인규
Nov 21 at 7:24




Generic / unknown HTTP error. I am using xampp's server, MySql, and I don't know why I get an error.
– 황인규
Nov 21 at 7:24












I use both too, not sure why, does it work for other things?
– comphonia
Nov 21 at 7:27




I use both too, not sure why, does it work for other things?
– comphonia
Nov 21 at 7:27












No. I only ran it on my laptop.
– 황인규
Nov 21 at 7:35






No. I only ran it on my laptop.
– 황인규
Nov 21 at 7:35














copy the new C# code, just tested it in unity and its working. the public string was messing it up, I also set it outside of Start()
– comphonia
Nov 21 at 7:41




copy the new C# code, just tested it in unity and its working. the public string was messing it up, I also set it outside of Start()
– comphonia
Nov 21 at 7:41












you should see the results as a unity debug, without having to go to the browser, so you know its posted
– comphonia
Nov 21 at 7:45




you should see the results as a unity debug, without having to go to the browser, so you know its posted
– comphonia
Nov 21 at 7:45


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405384%2fi-get-strange-results-when-i-access-the-sqlitedatabase-with-unity-c-sharp-via-xa%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen