0

我目前正在为 iOS 开发一个网络应用程序,但该应用程序无法正确连接。

当我尝试登录时,我收到以下 iOS 弹出窗口:index.html 错误。

当 PHP 文件在线时,

这是我的一些代码:

连接.php

<?php //Make connection with database
// Verbinden met MySQL Database
$host = "localhost"; // Welke server : localhost 
$username = "*******"; // Gebruikersnaam
$password = "****"; // Wachtwoord
$dbnaam = "*****"; // Naam van de database
$db_error1 = "<p>FOUT: verbinden met databaseserver is mislukt</p>"; // Foutmelding 1
$db_error2 = "<p>FOUT: selecteren van database is mislukt</p>"; // Foutmelding 2
$db_error3 = "<p>FOUT: sluiten van database is mislukt</p>"; // Foutmelding 3

// Verbinden met Databaseserver
$con=mysqli_connect($host, $username, $password, $dbnaam);// or die($db_error1);
// verbinden met de database
//mysql_select_db($dbnaam, $db) or die($db_error2);
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?>

演示.js

// define the URL of the server component
//var url ="http://www.jorisgraaumans.nl/dutchmobile/";
//var url = "http://localhost:8888/Mobile/Festival/";
var url = "http://www.rikvandoorn.com/mobile/";

// afvangen van het standaard submit event
// zie ook: http://api.jquery.com/submit/

$('#login').on('pageinit', function(event) {
    $('#loginForm').submit(function() {
        $.ajax({
            type: "POST",
            url: "processLogin.php",
            cache: "false",
            dataType: "json",
            data: {
                email : $('#email').val(),
                wachtwoord : $('#wachtwoord').val(),
            },
            success: function(phpData){ 
                $("#return").data("login", phpData.login);
                console.log("login is: "+ phpData.login);
                if(phpData['error'] == true){
                    $.mobile.changePage("#return", {
                        transition : "fade"
                    })
                } else {
                    $.mobile.changePage("#home", {
                        transition : "fade"
                    })
                }
            },  
            error: function(){
                    alert('Error');
            }                   
        }); 
        return false; // return false to prevent the default submit of the form to the server.
    });
    // end: pageinit loginForm  
});
$('#return').on('pageshow', function(event) {
    $("#error_message_log").empty();
    $("#error_message_log").prepend('<p>' +  $(this).data('login') + '</p>');
});

进程登录.php

<?php //process login form 

include 'http://www.rikvandoorn.nl/mobile/connect.php'; //connection to database
if(empty($_POST['email']) || empty($_POST['wachtwoord'])){
    $return['error'] = true;    //return error
    $return['login'] = 'Niet alle velden zijn ingevuld';
} else {
    $email = $_POST['email'];
    $wachtwoord = $_POST['wachtwoord'];

    //Check if user exists
    $sql = "SELECT * FROM gebruiker WHERE email = '$email'";
    $result = mysql_query($sql) or die(mysql_error());
    $num_rows = mysql_num_rows($result);    

    if($num_rows == 0){
        $return['error'] = true;
        $return['login'] = 'Gebruiker bestaat niet';
    } else {
        //Check if password is correct for user
        $sql_2 = "SELECT * FROM gebruiker WHERE email = '$email'  && wachtwoord = '$wachtwoord'";
        $query_2 = mysql_query($sql_2);
        $num_rows_2 = mysql_num_rows($query_2);
        if($num_rows_2 == 0){
            $return['error'] = true;
            $return['login'] = 'Wachtwoord onjuist';
        } else {
            $return['error'] = false;
            $return['login']['email'] = $email;
            $return['login']['wachtwoord'] = $wachtwoord;
        }
    }
}
echo json_encode($return);
4

1 回答 1

0

除非你用错别字弄乱了代码,否则你正在混合两个完全独立的 mysql 库:

$con=mysqli_connect($host, $username, $password, $dbnaam);// or die($db_error1);
          ^---note the presence of an 'i'

在其他脚本中:

$result = mysql_query($sql) or die(mysql_error());
               ^---note the LACK of an 'i'

mysql 和 mysqli不可互换,在一个中建立的连接对另一个完全没用。

mysql(没有i)库已过时且已弃用。只坚持使用 mysqli ( WITH an i)。

于 2013-07-02T15:58:30.533 回答