Create account MySQL/PHP not working need help

0 favourites
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • Hi!

    For some days im still trying to fix my "Create account" page.

    The page is build up with textboxes and a button.

    After submitting it will AJAX to my php script and SHOULD create a account.

    To bad it isn't working for ages now and i think i might oversee something.

    I could use some help on this one!

    What i got a.t.m. in Construct 2 is:

    <img src="http://akey.nl/scr1.png" border="0" />

    Fyi, i filled in the values manually atm just for testing. Normally i would: "cusername="& Username.Text &"".

    Now. My PHP script is:

    <?php 
    header('Access-Control-Allow-Origin: *');
    
    // SET DATABASE CONNECTION  
    define ("DB_HOST", "localhost"); // set database host
    define ("DB_USER", "!!"); // set database user
    define ("DB_PASS","!!"); // set database password
    define ("DB_NAME","!!"); // set database name
    
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
    $db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");
    
    $username = $_GET['cusername'];
    $pass = $_GET['cpass'];
    $retypepass = $_GET['cretypepass'];
    $email = $_GET['cemail'];
    $country = $_GET['ccountry'];
    
    // SET ALL FUNCTIONS  
    function isUserID($username)
    {
         if (preg_match('/^[a-z\d_]{5,20}$/i', $username)) {
              return true;
         } else {
              return false;
         }
    }
    
    function checkPwd($x,$y) 
    {
    if(empty($x) || empty($y) ) { return false; }
    if (strlen($x) < 4 || strlen($y) < 4) { return false; }
    
    if (strcmp($x,$y) != 0) {
     return false;
     } 
    return true;
    }
    
    function PwdHash($pwd, $salt = null)
    {
        if ($salt === null)     {
            $salt = substr(md5(uniqid(rand(), true)), 0, (int)SALT_LENGTH);
        }
        else     {
            $salt = substr($salt, 0, SALT_LENGTH);
        }
        return $salt . sha1($pwd . $salt);
    }
    $err = array();
    
    // Validate User Name
    if (!isUserID($username)) {
    $err[] = "ERROR - Invalid user name. It can contain alphabet, number and underscore.";
    //header("Location: register.php?msg=$err");
    //exit();
    }
    
    // Check User Passwords
    if (!checkPwd($pass,$retypepass)) {
    $err[] = "ERROR - Invalid Password or mismatch. Enter 5 chars or more";
    //header("Location: register.php?msg=$err");
    //exit();
    }
           
    // stores sha1 of password
    $sha1pass = PwdHash($pass);
    
    $rs_duplicate = mysql_query("select count(*) as total from members where username='$username'") or die(mysql_error());
    list($total) = mysql_fetch_row($rs_duplicate);
    
    if ($total > 0)
    {
    $err[] = "ERROR - The username already exists. Please try again with different username.";
    }
    
    if(empty($err)) {
    
    $sql_insert = "INSERT into `members`
                    ?(`password`,`date`,`country`,`email`,`username`)
                  VALUES
                  ('$sha1pass',now(),'$country','$email','$username')
                  ?";
                  ?
    mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());
    
      echo "Sign up complete!";
    
      exit();
    }
    ?>
    
      <?php     
          if(!empty($err))  {
           foreach ($err as $e) {
           ??echo "* $e";
           ??}     
           ?}else{
           ?}
          ?> 
    

    If i put in the link manually it works like a sharm and it will create my account. When i do the AJAX thingy in Construct 2 it won't work :(!

    Any 1 here that can see the problem?

    P.S! I know i can't test this in "Run Layout" mode. I export it before testing.

    Also i got a simple login to work so a connection worked before on a different script, same project.

    Thanks in advance!

  • For one you're posting in construct2 but your php is set up to $_get the info. Switch to a get in c2 and see if that works. :) might be more not sure i stopped when I saw that.

  • Hi Lanceal,

    Thanks for your reply.

    I'm afraid i already tried that. I am really desperate. For now, i tried it again with the GET in C2 ( Request ) but to bad still no result.

    A little more info i forgot. As you can see in my img, i did put up a "Error" text. Also this one is NOT changing. So that can be 2 things, or the error text isn't working in my CS2 or CS2 never contacts my php script.

  • Pul up the developer tools in your browser just before you login and watch for the expected get call. If it show up check the response to see what it says. If it doesn't then you never fired the event in c2.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hmm lemme look at my php script for a sec, brb. I used a similar php script in the past and I think I had a problem as well back then. I almost want to say it ended up being those tick marks ' were not all good. I'm probably not accurate though brb.

  • I pulled one of my public functions, as you can see I did skip the tick marks for the variables, albeit I can't for the life of me remember why. Maybe give it a shot without the variable ticks.

    public function addUserNotes($suids, $CID, $note){

        $query = $this->mysqli->prepare("INSERT INTO `Notes` (`Contact_ID`, `UID`, `Note`) VALUES (?, ?, ?)");

              $query->bind_param("sis", $CID, $suids, $note);

              

              $query->execute();

              $query->close();

    Note:

    I notice you declared php twice, I'm not a php expert so excuse me if it's an obvious answer. Can you declare php twice in the same script? What would be the benefits to doing that?

  • Hi Lanceal,

    Thanks for thinking with me.

    Yep that double php is possible but not needed. I now just got it in one ;-)!

    Without the ticks also not solved.

    Some thing is grinding my gear. As you can see in Construct 2, anything that will be echo'ed on my script should appear in my C2 application.

    This text is not updated at all. For me that looks like it is not contacting my script at all.

    I can put in the link manually with variables manually putted in and that works ( in my browser not in C2 ).

    In other works, the script itself works perfect.

    Even if C2 would not send the variables within the link, it has to result an error.

    Hmmm I really don't know what the problem is anymore :(.

    I even tried the things like updating the scripts permissions and stuff. I tried it all :(

    Is there anything i need to know about C2 in combination with PHP? Look as far as i understand in C2 i give the variables away and from that point off i can let my php do the work right?

  • Have you tried login out whatever comes from a "AJAX: On error" event ?

  • i have trying to use ajax with construct2 , but dont work with data :

    <font size="4"><font color=red>an error occurred with ajax : Refused to set unsafe header "Content-Length"</font></font>

    no data have sent to php script.

    but, if you put all data directly int the url, it's work perfectly.

    Maybe a problem with the AJAX plugin ?

  • And as kyat rid said you already tried to catch the text from an on error event? Would you mind sharing your website so people can try to log in and see what kind of error message if any apply? Are you familiar with developer tools in the browser? There would only be three outcomes I think in the tool once you click the button. One it echos back the desired result(error in your c2 implementation), an error would be attached pointing to the problem, or nothing happens meaning your button click action isn't working as desired. If you are familiar, try that, if not post a link so people on here can try for you :). I'm currently at a loss otherwise, sorry :(

  • Silly question, but the text you are inputting into and the layer it's on are both set to visible right?

  • Thanks for the reactions! All data i need is actually in the URL.

    On error event also not updating my "error text".. I must be doing something wrong here (ofc otherwise it would work..)

    If i export to HTML5 and upload it all that happens:

    Creating Application Cache with manifest http://*.nl/test/offline.appcache *.nl/:1
    Application Cache Checking event *.nl/:1
    Application Cache Downloading event *.nl/:1
    Application Cache Progress event (0 of 9) http://*.nl/test/index.html *.nl/:1
    Application Cache Progress event (1 of 9) http://*.nl/test/logo.png *.nl/:1
    Application Cache Progress event (2 of 9) http://*.nl/test/images/loginbutton-sheet0.png *.nl/:1
    Application Cache Progress event (3 of 9) http://*.nl/test/jquery-2.0.0.min.js *.nl/:1
    Application Cache Progress event (4 of 9) http://*.nl/test/c2runtime.js *.nl/:1
    Application Cache Progress event (5 of 9) http://*.nl/test/images/startscreenbackground-sheet0.png *.nl/:1
    Application Cache Progress event (6 of 9) http://*.nl/test/images/mainscreenbackground-sheet0.png *.nl/:1
    Application Cache Progress event (7 of 9) http://*.nl/test/images/createaccount-sheet0.png *.nl/:1
    Application Cache Progress event (8 of 9) http://*.nl/test/images/sprite-sheet0.png *.nl/:1
    Application Cache Progress event (9 of 9)  *.nl/:1
    Application Cache Cached event
    

    Whenever i press the button nothing happens.

    ,

    Yes everything is set to visible.

    I rather not share the link yet for some reasons, but i need every help i could. In the meantime i will make a second build so i can share it all. Thanks!

  • Ok here we go.

    Live test at: Link removed since fix

    Download C2 files: Link removed since fix

    In the CS2 files i updated the AJAX link again. It is NOT manually entered anymore now. Now it has to work from the forms you fill in.

    Btw i see that the labels are missing. Form as:

    Username

    Password

    Re-type password

    E-mail

    Country

    I would really appriciate the help!

    Thanks guys alot!

  • ok, simple fix. Open the createaccountscreen layout so the left side of the screen is filled with the layout properties. Change the event sheet from noe to signupscreen. That I'm guessing will fix your problem.

  • <img src="http://akey.nl/facewall.jpg" border="0" />

    Thanks alot! Really.. That Facewall isn't even enough for this dumb mistake. I feal terrible wasting all these hours on... yes... just that.. Wrong event sheet..

    Well atleast im happy my script works as a charm!

    Thanks all!

    For my stupidity i will create a good sign up / login script tutorial soon.

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