it inserts the value user = $user pass = $pass
instead of the actual variable so naturally i attempted removing the quotes around the variables but then i get a database error claiming that there is an ‘unexpected T_variable’
you have $user and $pass set to integer valies. mysql only interperates strings.
You forgot the semi-colons at the end of the variable declarations.
VALUES ( NULL, ‘$user’, MD5(‘$pass’)); is inserting the STRING $user and the hash of the STRING $pass. you want the data of the variables themselves, so you have to leave out the apostrophies on the variables.
Okay im going to try that out now! thank you all for replying.
And thanks for the criticm, in the actualy statement im actaully using addslashes command to prevent injection is this helpful or is there some additional security measures i should take?
Yea, I aware that this code is very vulnerable, however he didn’t ask about that (Although it is probably a good thing to point out). I simply answered his questions.
Thank you for your reply Antitheory! (and you just deleted you post why?)
Here is the code i cannot get to work, unity is passing the username and password for registration to php but php is refusing to pass my variables to SQL here is my exact php passing code, just the snippet that wont work.
I am not sure how you go about connecting to your database as it’s not shown here, but make sure you are successfully connecting. That’s the first step. Also, make sure your database is setup to match your SQL statement.
@mysql_query is not correct SQL (to my knoweldge) remove the @ in front of it.
What is the URL to your PHP script? I am going to test it manually in the browser to make sure it isn’t something on the client-side.
The url is LINK REMOVED
but for you it should return database error no matter what as you need to have to unity code to pass the variables in the first place
In most cases mysql_real_escape_string will save you. Most cases but not all cases, especially if you are using integer fields like that for $user and $password… My guess is that you aren’t, and this was a mistaken assumption by jonbonazza… How many sites have integer passwords?
$host = “HIDDEN_FROM_FORUM”; //put your host here
$user = “HIDDEN_FROM_FORUM”; //in general is root
$password = “HIDDEN_FROM_FORUM”; //use your password here
$dbname = “HIDDEN_FROM_FORUM”; //your database
mysql_connect($host, $user, $password) or die(“Cant connect into database”);
mysql_select_db($dbname)or die(“Cant connect into database”);
It’s casuing an error as you’re not quoting the strings. It should work like this
$sql = “INSERT INTO scores (id, name, password) VALUES (NULL, ‘$nick’, MD5(‘$pass’))”;
$result_id = @mysql_query($sql) or die(“DATABASE ERROR!”);
That corrected I would highly recommend to not use that code. It’s an SQL injection waiting to happen.
I recommend not using the old mysql extension but switch to Mysqli or PDO and use prepared statements.
Also when developing/testing you should not use @ in front of a command as it supresses the errormessage which would’ve been a lot more helpful then the “DATABASE ERROR”.
Mmkay, well it definitely is in the PHP script. Also, I have a question. In the SQL statement, you have an id feild, but always set it to NULL.
If this is your primary key, then you need to have it. Furthermore, since you are always setting it to null, I am curious if you even have it in your database?
Note that I added single-quotation marks around $nick and $pass… Without them it wont work unless $nick and $pass are integers. I haven’t used the SQL MD5 function before but I can only assume it is expecting a string.Your database needs to have the fields name and password as type varchar (or some other text-based field type like “text” or something. I would use varchar with short things like usernames and passwords);
if you find that this works but it’s literally putting in the word “$nick” into the database then it’s possible your version of PHP is strange and not parsing the variable name. In that case you will need to do this:
Thanks Antitheory, and yes i noticed that after i commented that but uploaded the new script with the correction immidiately afterwards! thanks for all of your help!
Also I would highly recommend you remove the post with the link to your php script until you have implemented proper escaping of the variables. Some unscrupulous person could cause some damage right now if the code you posted is all you have.
I see, well what if $nick was asssigned a string already… wouldn’t that mean that using $nick without the apostrophies would be correct? I am just trying to figure out why $nick and $pass would be assigned integers to begin with… that’s what I was trying to get at…