-2

I have this AJAX sign up form, and I want to make a gear wheel play like that

whenever the server has signed up i want this bar to change to green, so what's I've done is echo the names of the function I wanted to call like so:

            echo "passed";
            if ($query = $sql->prepare("INSERT INTO business(password , username , bname) VALUES(? , ? , ?)")) {
                $query->bind_param("sss" , $password , $username , $bname );
                $query->execute();
            } else {
                printf("ErrorMessage: %s \n" , $sql->error);
            }

            if ($query2 = $sql->prepare("INSERT INTO user_business_data(email , firstname) VALUES(? , ? )")) {
                $query2->bind_param('ss' , $email , $firstname);
                $query2->execute();
            } else {
                printf('ErrorMessage: %s\n' , $sql->error);
            }
            $query3 = mysqli_query($sql ,"INSERT INTO user_time_stamp_business(time_stamp) VALUES (CURRENT_TIMESTAMP)");

            $query2->close();
            $query->close();
            $sql->close();
            if ($query && $query2) {
                sleep(3);
                echo "success";
                exit;
            } 

                            if (http.responseText == "passed") {
                            works();
                            document.getElementById("main-container").style.transform = "translateY(8%)";
                        } else if (http.responseText == "success") {
                            document.getElementById("alert").style.backgroundColor = "green";
                        }

The problem is that it creates a long string AND that it all comes together and not "passed" alone and "success" after

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Guy Sudai
  • 36
  • 5
  • **Never store plain text passwords!** Please use PHP's [built-in functions](http://jayblanchard.net/proper_password_hashing_with_PHP.html) to handle password security. If you're using a PHP version less than 5.5 you can use the `password_hash()` [compatibility pack](https://github.com/ircmaxell/password_compat). Make sure you ***[don't escape passwords](http://stackoverflow.com/q/36628418/1011527)*** or use any other cleansing mechanism on them before hashing. Doing so *changes* the password and causes unnecessary additional coding. – Jay Blanchard Mar 06 '17 at 16:54
  • they're hashed before that dont worry.... – Guy Sudai Mar 06 '17 at 16:55
  • It's just a small piece of my code – Guy Sudai Mar 06 '17 at 16:55
  • Create a proper response return, for instance in a JSON-encoded array, and parse that array on return for either errors, success or whatever else you need. – junkfoodjunkie Mar 06 '17 at 16:57
  • can you give me an example? – Guy Sudai Mar 06 '17 at 16:58

1 Answers1

0

You could use echo "passed", and then echo "\n" . "success";.

Afterwards, you'd split the http.responseText variable like this: http.responseText.split("\n").
Then you can get the last item of the returned array and use it as your last script response.

This new variable should have what you need:

var status = http.responseText.split("\n").reverse()[0];

(see Javascript how to split newline)

Community
  • 1
  • 1
Matiboux
  • 112
  • 8
  • How does it fix the problem that they come together though? – Guy Sudai Mar 06 '17 at 17:19
  • It's fixed by adding a new line after each status. ("\n") If you want, you can use any other separator ! Don't forget to update the `.split(SELECTOR)` javascript function – Matiboux Mar 06 '17 at 17:50