Registration form

You need to test the PHP script through a web browser. If you would share the URL it would be much easier, but you need to bring up Firefox, Chrome, Safari, Edge, etc. and in the location bar type in:

https://your.website.com/?Register=1&username=testuser&password=testpassword&password2=testpassword&email=test%40email.com

and see what shows on your browser screen.

Now there are still several things wrong with your script. But you need to learn to debug before you go on. Copy and paste what your browser says after hitting that URL (and putting in your real server address)

Rob

http://hash.comxa.com/

That’s the real link

Okay, now type:

http://hash.comxa.com/register.php?Register=1&username=testuser&password=testpassword&password2=testpassword&email=test%40email.com

into a browser and what happens?

You should also make sure you are connecting to your database properly.

test@email.com Fatal error: Call to undefined function password\_hash() in /home/a2677272/public\_html/register.php on line 35

So what you’re seeing is your script take the email address that I hand URL encoded (@ signs are not safe to pass on a URL) and your PHP script at least got to the point of where it’s echoing out the decoded email address. So there were no errors up to that point (still doesn’t mean it worked right). But then it hit an error:

Undefined function password_hash().

This is an error in your script that you need to fix it before you can find more errors. You have more errors too. This is how you debug API endpoints. Getting Corona involved at this point isn’t doing you any good.

This specific error tells me your PHP is an older version. The password_hash() function was not added until PHP 5.5. (though I’ve seen references to it being 5.4). It’s a shame, they put a lot of thought into that function.  This will get you started for older PHP’s:
 

http://stackoverflow.com/questions/25372636/password-hash-equivalent-for-php-5-4

Once you fix this problem, and you reload your browser you will get additional errors. Work through them the best  you can.

I fixed my PHP code and everything is good now , no errors , but my corona sdk code still isn’t working . Are you able to help me now ?

Are the results of your web browser try getting into your database?

And post your latest PHP script please.

I don’t understand the question 

Do you have a way of seeing what all is in your database table?

Also please post your latest PHP script. It’s not outputting anything on success.

\<?php $con = mysqli\_connect("mysql9.000webhost.com", "a2677272\_root", "bigman23", "a2677272\_hash"); // Check connection if ($con-\>connect\_error) { die("Check connection."); } if(isset($\_GET['Register'])) { if ($\_GET['password'] == $\_GET['password2']) { $username = mysqli\_real\_escape\_string($con, $\_GET["username"]); $pw= mysqli\_real\_escape\_string($con, $\_GET["pw"]); // you don't need password2 any more after this point $email = mysqli\_real\_escape\_string($con, $\_GET["email"]); // validate and sanitize all of these inputs // and see that they are not blank at the same time // Do your MySql here to find the $username and // bring out result of find in $username\_result $result = mysqli\_query($con ,"SELECT \* FROM users WHERE username='" . $username . "' AND email='" . $email . "'"); if(mysqli\_num\_rows($result) \> 0) { echo "User exist"; } else { $sql = ("UPDATE users SET username='" . $username . "' , pw='" . $pw. "' , email='" . $email. "'"); if(mysqli\_query($con, $sql)){ // if insert checked as successful echo username and password saved successfully }else{ echo mysqli\_error($con); } }} }else{ echo "The passwords do not match."; // and send them back to registration page } ?\>

Great you’re getting very close with this, but I don’t believe the PHP script is working.

$sql = ("UPDATE users SET username='" . $username . "' , pw='" . $pw. "' , email='" . $email. "'");

Updates an existing record. It does not create a new record. If this actually works, you’re updating every database record to have those values. UPDATESs need a WHERE clause to limit changes to just the specific record(s) you want to update. But you’re registering a new user. This person isn’t in the database yet. You want to do an INSERT not an UPDATE. Since I now know you’re using the string concatenation method of building queries, you need to do:

$sql = "INSERT INTO users (username, pw, email) VALUES(null, '" . $username . "', '" . $pw . "', '" . $email . "')"; 

or

$sql = "INSERT INTO users (username, password, email) VALUES(null, '" . $username . "', '" . $pw . "', '" . $email . "')";

depending on what you named the column in the database table for password. I’m not sure you named it “pw”. Database column names and PHP variables can be different. This is why I think you need to look in your database management tools and see what all data is in the database and what the column names are.

Finally there is this code:

if(mysqli\_query($con, $sql)){ // if insert checked as successful echo username and password saved successfully &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }else{ echo mysqli\_error($con); } 

If the query is successful you don’t output anything so there is nothing for your Corona/Lua network.request() to process. You will only get errors. You need to add an “echo” statement in there. Perhaps something as simple as:

echo “Success”;

After you fix these things, we can look at the Lua script.

Rob

Column count doesn't match value count at row 1

This is what I get 

\<?php $con = mysqli\_connect("mysql9.000webhost.com", "a2677272\_root", "bigman23", "a2677272\_hash"); // Check connection if ($con-\>connect\_error) { die("Check connection."); } if(isset($\_GET['Register'])) { if ($\_GET['password'] == $\_GET['password2']) { $username = mysqli\_real\_escape\_string($con, $\_GET["username"]); $pw= mysqli\_real\_escape\_string($con, $\_GET["pw"]); // you don't need password2 any more after this point $email = mysqli\_real\_escape\_string($con, $\_GET["email"]); // validate and sanitize all of these inputs // and see that they are not blank at the same time // Do your MySql here to find the $username and // bring out result of find in $username\_result $result = mysqli\_query($con ,"SELECT \* FROM users WHERE username='" . $username . "' AND email='" . $email . "'"); if(mysqli\_num\_rows($result) \> 0) { echo "User exist"; } else { $sql = "INSERT INTO users (username, pw, email) VALUES(null, '" . $username . "', '" . $pw . "', '" . $email . "')"; if(mysqli\_query($con, $sql)){ // if insert checked as successful echo username and password saved successfully echo"success"; }else{ echo mysqli\_error($con); } } } }else{ echo "The passwords do not match."; // and send them back to registration page } ?\>

I’m not an expert at PHP but I don’t think 

$result = mysqli\_query($con ,"SELECT \* FROM users WHERE username='" . $username . "' AND email='" . $email . "'");

is running the way we think it will . I want the query to check if the username and email the user enters is already in the database . The way I see it is running is that if any username or email is in the database it will automatically say that the user exists 

$result = mysqli_query($con ,“SELECT * FROM users WHERE username=’” . $username . “’ AND email=’” . $email . “’”);

will get (SELECT) all fields (*) from the table “users” if the username column is an exact match to the value held in the $username variable and the email column is an exact match to the value held in the $email variable and it will return all records that match.

In the next lines:

if(mysqli\_num\_rows($result) \> 0) { echo "User exist"; }

You test to see how many records are returned. If it found any, then it outputs the string “User exist”. This I believe is working properly. I used the same name/mail I used earlier and it output “User exist”.

The “else” part of that if statement happens when it doesn’t find any one and that’s where you need to do a query to INSERT the record in the database.

But here is where you might have a problem. And this is likely my error, but it’s because I don’t know your database scheme. I cant see how you have the table defined in MySQL. This is the current command to insert data into the DB:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sql = "INSERT INTO users (username, pw, email) VALUES(null, '" . $username . "', '" . $pw . "', '" . $email . "')";

Your script is giving an error about a column count not matching. That’s because the first set of parens: (username, pw, email) defines three fields we will be inserting data into. The parans after VALUES is defining four things null, a string with the value from $username a string with the value from $pw and a string with the value from $email.  To fix this error remove the null, and that will make the columns match. You likely have an autoincrementing “id” column (the “null”) and you could specify that in the first parens, but since I can’t see that, lets go with what we know will work and take the null, (including the comma) out.

This leads us to our next problem. In the first parens you’re saying your database table has columns named “username”, “pw” and “email”. I would be willing to be that’s wrong and the column names are really “username”, “password” and “email”. If I’m right, you will get another error about an undefined column. Change the pw in the first parens to password if this is the case. Leave the second $pw alone. That’s a variable with your encrypted password in it.

It’s way late here where I am so I won’t be responding again until tomorrow.

Rob

In the link you gave me : http://hash.comxa.com/register.php?Register=1&username=testuser&password=testpassword&password2=testpassword&email=test%40email.com

It says success , but in my link I’m getting one of my else statements : passwords do not match . 

In my database the fields are : id , username , pw and email 

Why don’t you just check the passwords in lua

You are supposed to use 3 equal signs

Now i’m getting the else statement that says user exists