Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Login mysql_query()的Php问题_Login_Mysql_Php_Phpmyadmin - Fatal编程技术网

Login mysql_query()的Php问题

Login mysql_query()的Php问题,login,mysql,php,phpmyadmin,Login,Mysql,Php,Phpmyadmin,我的php代码一直有问题。我似乎从@mysql\u query()得到一个错误 以下是我的php代码: <?php // A simple PHP script demonstrating how to connect to MySQL. // Press the 'Run' button on the top to start the web server, // then click the URL that is emitted to the Output tab of the co

我的php代码一直有问题。我似乎从
@mysql\u query()
得到一个错误

以下是我的php代码:

<?php
// A simple PHP script demonstrating how to connect to MySQL.
// Press the 'Run' button on the top to start the web server,
// then click the URL that is emitted to the Output tab of the console.

$servername = getenv('IP');
$username = getenv('C9_USER');
$passwordp = "";
$database = "game_database";
$dbport = 3306;

// Create connection
mysql_connect($servername, $username, $passwordp, $dbport)or die("Cant Connect to server");
mysql_select_db($database) or die("Cant connect to database");
// Check connection


$Email = $_REQUEST["Email"];
$Password= $_REQUEST["Password"];

if (!$Email || !$Password){
echo"Email or password must be used";
}
else{
$SQL = "SELECT * FROM 'users' WHERE Email = '"  . $Email ."'";
$result_id = @mysql_query($SQL) or die("Database Error");
$Total = mysql_num_rows($result_id);
if ($Total){
    $datas = @mysql_fetch_array($result_id);
    if (strcmp($Password, $datas["Password"])){
                $sql2 = "SELECT Characters FROM users WHERE Email = '" . $Email ."'";
                $result_id2 = @mysql_query($sql2) or die("Database Error!!!");
                while ($row = mysql_fetch_array($result_id2)){
                    echo $row ["Characters"];
                    echo ":";
                    echo "Success";
                }
    }
    else{
        echo "WrongPassword";
    }
    }else {
        echo "NameDoesNotExist";
    }
}

?>

当我从unity编辑器中按play时,我从$result\u id上的@mysql\u query()中得到错误:“数据库错误”。

使用查询字符串作为如下格式


“从
测试
成员
中选择
m
名称
其中
name
=%s或
id
=%d或
sex
在(%a)”,“邪恶的'注入','NaN',数组('男','女','两个','其他',“外星人引号'男')

试着想想你的查询是否有错误,要做到这一点,你必须在调用mysql\u query()之后调用mysql\u error()函数。试着不要使用“@”仅仅是mysql\u query警告:PHP
mysql\u query()
函数(以及所有其他
mysql\u xxx()
函数)在最近的PHP版本中已被弃用,并将在PHP的下一个版本中完全删除。你不应该使用它。如果您只是在学习PHP,并且这是推荐给您的,那么您需要找到一个更好、更新的教程。如果您使用的是现有的代码库,那么您的代码需要更新。无论哪种方式,您都需要切换到使用PHP中提供的较新API;即
mysqli
PDO
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class LoginScript : MonoBehaviour {
#region Variables
//Static Variables
public static string Email = "";
public static string Password = "";
//Private Variables
private string createAccountUrl = "https://credmanager-rowanharley.c9.io/createaccount.php";
private string loginUrl = "https://credmanager-rowanharley.c9.io/loginaccount.php";
private string ConfirmPass= "";

private string CreateEmail = "";
private string CreatePassword = "";
//Public Variables
public string currentMenu = "Login";

//GUI test section
public float X;
public float Y;
public float Width;
public float Height;
#endregion
    // Use this for initialization
    void Start () {

    }

    void OnGUI(){
        //If current menu is = login call login screen
        if (currentMenu == "Login"){
            LoginGUI();
        }
        //If current menu is = Create Account call CreateAccount screen
        else if(currentMenu == "CreateAccount"){
            CreateAccountGUI();
        }
    }
    //This method will login to accounts
    void LoginGUI(){
        GUI.Box (new Rect (210, 15, 300, 300), "Login");
        if (GUI.Button (new Rect (250, 275, 105, 35), "Register Now!!!")) {
            currentMenu = "CreateAccount";
        }
        if (GUI.Button (new Rect (370, 275, 105, 35), "Login!")) {
            StartCoroutine(LoginAccount());
        }
        GUI.Label(new Rect(225, 55, 290, 100), "Before Continuing you need to login or register.");

        GUI.Label(new Rect(215, 102, 100, 100), "Email:");
        Email = GUI.TextField (new Rect (330, 100, 150, 25), Email);

        GUI.Label(new Rect(215, 150, 100, 100), "Password:");
        Password = GUI.TextField (new Rect (330, 147, 150, 25), Password);
    }
    void CreateAccountGUI(){
        GUI.Box (new Rect (210, 15, 300, 300), "Register to save progress");
        if (GUI.Button (new Rect (250, 275, 105, 35), "Back")) {
            currentMenu = "Login";
        }
        GUI.Label(new Rect(225, 55, 290, 100), "Register NOW!!!");

        GUI.Label(new Rect(215, 102, 100, 100), "Email:");
        CreateEmail = GUI.TextField (new Rect (330, 100, 150, 25), CreateEmail);

        GUI.Label(new Rect(215, 150, 100, 100), "Password:");
        CreatePassword = GUI.TextField (new Rect (330, 147, 150, 25), CreatePassword);

        GUI.Label(new Rect(215, 198, 122, 100), "Confirm Password:");
        ConfirmPass = GUI.TextField (new Rect (330, 194, 150, 25), ConfirmPass);



        GUI.Box (new Rect (210, 15, 300, 300), "Register to save progress");
        if (GUI.Button (new Rect (250, 275, 105, 35), "Back")) {
            currentMenu = "Login";
        }
        if (GUI.Button (new Rect (370, 275, 105, 35), "Create Account")) {
            if (CreatePassword == ConfirmPass){
                StartCoroutine("CreateAccount");

            }
            else{
                Debug.Log("Both Passwords are not the same");
            }
        }
    }



    IEnumerator CreateAccount(){
        //this sends info to php form
        WWWForm CreateAccountForm = new WWWForm ();
        CreateAccountForm.AddField ("Email", CreateEmail);
        CreateAccountForm.AddField ("Password", CreatePassword);

        WWW CreateAccountWWW = new WWW (createAccountUrl, CreateAccountForm);
        yield return CreateAccountWWW;

        if (CreateAccountWWW.error != null) {
            Debug.LogError ("Failed to Create Account. Is Internet On? Is URL Correct? Error Message: " + CreateAccountWWW.error);
        } else {
            string CreateAccountReturn = CreateAccountWWW.text;
            Debug.Log("Successfully Created Account " + CreateEmail);
            Application.LoadLevel("MainScene");
        }
    }

    IEnumerator LoginAccount(){
        Debug.Log ("Attempting to login...");
        WWWForm Form = new WWWForm ();
        Form.AddField ("Email", Email);
        Form.AddField ("Password", Password);
        WWW LoginAccountWWW = new WWW (loginUrl, Form);
        yield return LoginAccountWWW;
        if (LoginAccountWWW.error != null) {
            Debug.LogError("Problem with Database. Error Message: " + LoginAccountWWW.error);
        } 
        else {
            string LogText = LoginAccountWWW.text;
            Debug.Log(LogText);
            string[] LogTextSplit = LogText.Split(':');
            if (LogTextSplit[1] == "Success"){
                Application.LoadLevel("MainScene");
            }
        }
    }
}