Create account MySQL/PHP not working need help

Get help using Construct 2

Post » Thu Jul 04, 2013 9:10 pm

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:


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

Now. My PHP script is:
[CODE]
<?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{
       }
      ?>
[/CODE]

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!Allardje2013-07-04 21:34:46
B
10
S
4
G
3
Posts: 176
Reputation: 2,539

Post » Thu Jul 04, 2013 9:39 pm

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.
www.h1k3.tech

We are here for you!
B
90
S
24
G
16
Posts: 716
Reputation: 17,022

Post » Thu Jul 04, 2013 11:55 pm

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.
Allardje2013-07-04 23:56:10
B
10
S
4
G
3
Posts: 176
Reputation: 2,539

Post » Fri Jul 05, 2013 2:32 am

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.
www.h1k3.tech

We are here for you!
B
90
S
24
G
16
Posts: 716
Reputation: 17,022

Post » Fri Jul 05, 2013 2:40 am

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.
www.h1k3.tech

We are here for you!
B
90
S
24
G
16
Posts: 716
Reputation: 17,022

Post » Fri Jul 05, 2013 2:44 am

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?lanceal2013-07-05 02:47:01
www.h1k3.tech

We are here for you!
B
90
S
24
G
16
Posts: 716
Reputation: 17,022

Post » Fri Jul 05, 2013 10:28 am

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?Allardje2013-07-05 10:32:02
B
10
S
4
G
3
Posts: 176
Reputation: 2,539

Post » Fri Jul 05, 2013 1:21 pm

Have you tried login out whatever comes from a "AJAX: On error" event ?
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
296
S
119
G
96
Posts: 7,332
Reputation: 71,306

Post » Fri Jul 05, 2013 1:57 pm

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

an error occurred with ajax : Refused to set unsafe header "Content-Length"

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 ?
B
38
S
13
G
4
Posts: 152
Reputation: 5,147

Post » Fri Jul 05, 2013 2:07 pm

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 :(
www.h1k3.tech

We are here for you!
B
90
S
24
G
16
Posts: 716
Reputation: 17,022

Next

Return to How do I....?

Who is online

Users browsing this forum: NN81, Seruza and 9 guests