Ajax & PHP & Database

0 favourites
  • 15 posts
From the Asset Store
Paypal PHP Supports multiple platforms, Web/html5 Android, IOS. (Including storing transaction data)
  • Hello,

    i followed this tutorial.

    I got always ID = 0 wich means there is something wrong because the entry's in the database are correct.

    here my Events

    thanks

    yonda

    updated pic

  • I cant see anything on that photo. Could you share your .capx or upload a larger photo, with area in mind, cropped.

  • I cant see anything on that photo. Could you share your .capx or upload a larger photo, with area in mind, cropped.

    Its done, the image should now expand on click

  • Should that be 'login.php' and not 'Login.php'.

  • Should that be 'login.php' and not 'Login.php'.

    changed it but still not working

  • Try and get the page working in the browser first. You should be able to go to

    http://game.stch.de/login.php?fname='Username'&fpass='Password'

    and see the expected output.

  • My login.php

    <?php

    $username = $_GET['fname'];

    $password = $_GET['fpass'];

    $con=mysqli_connect("localhost","dbuser","dbpass","database");

    // Check connection

    if (mysqli_connect_errno())

    {

    echo "Failed to connect to MySQL: " . mysqli_connect_error();

    }

    <br>    $qz = "SELECT id FROM members where username='".$username."' and password='".$password."'" ;

    $qz = str_replace("\'","",$qz);

    $result = mysqli_query($con,$qz);

    <br>    while($row = mysqli_fetch_array($result))

    {

    echo $row['id'];

    }

    <br>    mysqli_close($con);

    ?>

    plz help

  • anyone an idea?

  • try without adding those ' characters to the ajax string. I have a rather complex login using ajax and get. What kept messing me up was exactly that.

  • try without adding those ' characters to the ajax string. I have a rather complex login using ajax and get. What kept messing me up was exactly that.

    I did that, but still not working

  • Really silly question, but this line here

    $con=mysqli_connect("localhost","dbuser","dbpass","database");

    Those are not your actual values correct?

  • Really silly question, but this line here

    $con=mysqli_connect("localhost","dbuser","dbpass","database");

    Those are not your actual values correct?

    Correct! you wouldn't post them in a forum ;-)

  • Maybe your query statement is wrong? Here is a copy of one of the functions in the library I'm using.

    public function getUserNotes($suids, $CID, $page, $limit){

        //$result = $this->mysqli->prepare("SELECT * FROM `Contacts` WHERE `uid` = $suids ORDER BY `Next_Contact` ASC ");

        $result = $this->mysqli->query("SELECT * FROM `Notes` WHERE `UID` = $suids AND `Contact_ID` = $CID ORDER BY `Date` DESC LIMIT $page , $limit");

        $rows = array();

        while($row = $result->fetch_assoc()){

                 $rows[] = $row;

        }

        return $rows;

    }

    Notice I'm not using any ' or seperating variable from the string with " and . marks. Although for good measure I am using backticks ` to wrap around the table and reference points. Here is a copy of my login function as well. Maybe you can pull some ideas from it.

    public function login($username, $password)

         {

              $return = array();

              

              if($this->isBlocked($_SERVER['REMOTE_ADDR']))

              {

                   $return['code'] = 0;

                   return $return;

              }

              else

              {

                   if(strlen($username) == 0) { $return['code'] = 1; $this->addAttempt($_SERVER['REMOTE_ADDR']); return $return; }

                   elseif(strlen($username) > 30) { $return['code'] = 1; $this->addAttempt($_SERVER['REMOTE_ADDR']); return $return; }

                   elseif(strlen($username) < 3) { $return['code'] = 1; $this->addAttempt($_SERVER['REMOTE_ADDR']); return $return; }

                   elseif(strlen($password) == 0) { $return['code'] = 1; $this->addAttempt($_SERVER['REMOTE_ADDR']); return $return; }

                   elseif(strlen($password) != 40) { $return['code'] = 1; $this->addAttempt($_SERVER['REMOTE_ADDR']); return $return; }

                   else

                   {

                        $plainpass = $password;

                        $password = $this->getHash($password);

                        

                        if($userdata = $this->getUserData($username))

                        {

                             if($password === $userdata['password'])

                             {

                                  if($userdata['isactive'] == 1)

                                  {

                                       $sessiondata = $this->addNewSession($userdata['uid']);

                                       $return['code'] = 4;

                                       $return['session_hash'] = $sessiondata['hash'];

                                       

                                       $this->addNewLog($userdata['uid'], "LOGIN_SUCCESS", "User logged in. Session hash : " . $sessiondata['hash']);

                                       

                                       return $return;

                                  }

                                  else

                                  {

                                       $this->addAttempt($_SERVER['REMOTE_ADDR']);

                                  

                                       $this->addNewLog($userdata['uid'], "LOGIN_FAIL_NONACTIVE", "Account inactive");

                                  

                                       $return['code'] = 3;

                                       

                                       return $return;

                                  }

                             }

                             else

                             {

                                  $this->addAttempt($_SERVER['REMOTE_ADDR']);

                             

                                  $this->addNewLog($userdata['uid'], "LOGIN_FAIL_PASSWORD", "Password incorrect : {$plainpass}");

                             

                                  $return['code'] = 2;

                                  

                                  return $return;

                             }

                        }

                        else

                        {

                             $this->addAttempt($_SERVER['REMOTE_ADDR']);

                        

                             $this->addNewLog("", "LOGIN_FAIL_USERNAME", "Attempted login with the username : {$username} -> Username doesn't exist in DB");

                        

                             $return['code'] = 2;

                             

                             return $return;

                        }

                   }

              }

         }

  • My login.php

    <?php

    $username = $_GET['fname'];

    $password = $_GET['fpass'];

    $con=mysqli_connect("localhost","dbuser","dbpass","database");

    // Check connection

    if (mysqli_connect_errno())

    {

    echo "Failed to connect to MySQL: " . mysqli_connect_error();

    }

    <br>    $qz = "SELECT id FROM members where username='".$username."' and password='".$password."'" ;

    $qz = str_replace("\'","",$qz);

    $result = mysqli_query($con,$qz);

    <br>    while($row = mysqli_fetch_array($result))

    {

    echo $row['id'];

    }

    <br>    mysqli_close($con);

    ?>

    plz help

    Those <br> tags shouldn't be there anyway. I see they're in the tutorial code too - must be a copy-paste error.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • >

    > My login.php

    >

    > <?php

    > $username = $_GET['fname'];

    > $password = $_GET['fpass'];

    > $con=mysqli_connect("localhost","dbuser","dbpass","database");

    > // Check connection

    > if (mysqli_connect_errno())

    > {

    > echo "Failed to connect to MySQL: " . mysqli_connect_error();

    > }

    > <br>    $qz = "SELECT id FROM members where username='".$username."' and password='".$password."'" ;

    > $qz = str_replace("\'","",$qz);

    > $result = mysqli_query($con,$qz);

    > <br>    while($row = mysqli_fetch_array($result))

    > {

    > echo $row['id'];

    > }

    > <br>    mysqli_close($con);

    > ?>

    >

    > plz help

    Those <br> tags shouldn't be there anyway. I see they're in the tutorial code too - must be a copy-paste error.

    Nice that was the Error

    Thx you are my hero for today ;-)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)