linus72982 Posted March 7, 2011 Share Posted March 7, 2011 I have a newUser function in a class (database) that attempts to input all the post data from a registration (after it validates it all of course). Here is my function: public function newUser($properties, $validated, $userLevel, $validationCode) { $qualityControl = new QualityControl; $properties = $this->escapeString($_POST); $properties['password'] = $qualityControl->encryptData($properties['password']); $time = gmmktime(); $query = "INSERT INTO 'TABLE_NAME' (handle, email, userLevel, password, banned, dateJoined, validated, validtionCode) VALUES ('$properties[username]','$properties[email]','$userLevel','$properties[password]',0,'$time','$validated','$validationCode')"; return mysql_query($query, $this->connection); } I am getting an error in that my query is not inserting, no errors come up with mysql_error if I toss that in after the query and this function appears to run fine as it returns and the rest of the script is run. I have a feeling it has to do with either my sql syntax or the escapeString function. Escape string is a function that is "supposed" to escape a string passed to it or iterate through an entire array it is passed, here is the code for it: private function escapeString($data) { if (is_array($data)) { foreach ($data as &$value) $value = mysql_real_escape_string($value); return $data; } return mysql_real_escape_string($data); } If there error isn't in either of these two areas, it might be the encryptData function? All it is doing is md5ing + salting the password and returning the result. Here is that function if you need it: return md5(SALT.$data); Very simple, I don't think the error is there. The globals I'm using are all defined correctly so that shouldn't be a problem either. I've been looking at it for the past hour and can't figure out why my stuff won't get into the database. Oh, here's the beginning of the database class that opens the database and such, I'm not getting any errors from it. class Database { var $connection; public function __construct() { $qualityControl = new QualityControl; $this->connection = mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD) or die(mysql_error()); mysql_select_db(DB_NAME, $this->connection) or die(mysql_error()); } Thank you for any help! Also, please excuse some of the sloppiness like the error handling not being graceful, etc, I usually pretty that stuff up after I'm done with the script. -Adam Quote Link to comment https://forums.phpfreaks.com/topic/229822-not-sure-where-my-error-is-mysql-maybe/ Share on other sites More sharing options...
redarrow Posted March 7, 2011 Share Posted March 7, 2011 look fishy i agree, does it get any info in the database yet? <?php $query = "INSERT INTO 'TABLE_NAME' (handle, email, userLevel, password, banned, dateJoined, validated, validtionCode) VALUES ('$properties[username]','$properties[email]','$userLevel','$properties[password]',0,'$time','$validated','$validationCode')"; ?> try this way? <?php $query = "INSERT INTO 'TABLE_NAME' (handle, email, userLevel, password, banned, dateJoined, validated, validtionCode) VALUES ('".$properties[username]."','".$properties[email]."','$userLevel','".$properties[password]."',0,'$time','$validated','$validationCode')"; Quote Link to comment https://forums.phpfreaks.com/topic/229822-not-sure-where-my-error-is-mysql-maybe/#findComment-1183786 Share on other sites More sharing options...
redarrow Posted March 7, 2011 Share Posted March 7, 2011 This will insert, my god please! lets all php pray <?php $query = "INSERT INTO 'TABLE_NAME' (handle, email, userLevel, password, banned, dateJoined, validated, validtionCode) VALUES ('".$properties['username']."','".$properties['email']."','$userLevel','".$properties['password']."',0,'$time','$validated','$validationCode')"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/229822-not-sure-where-my-error-is-mysql-maybe/#findComment-1183787 Share on other sites More sharing options...
linus72982 Posted March 7, 2011 Author Share Posted March 7, 2011 Nope, no go on any of these. What are the rules about using variables within a query? Do you have to encase all variables with ' ' or just string variables? Quote Link to comment https://forums.phpfreaks.com/topic/229822-not-sure-where-my-error-is-mysql-maybe/#findComment-1183817 Share on other sites More sharing options...
linus72982 Posted March 7, 2011 Author Share Posted March 7, 2011 When I add an if to check if !$result and then die with a message, I get the message - so the query is coming back false. If that's the case, shouldn't a mysql_error show up? It isn't. Quote Link to comment https://forums.phpfreaks.com/topic/229822-not-sure-where-my-error-is-mysql-maybe/#findComment-1183822 Share on other sites More sharing options...
linus72982 Posted March 7, 2011 Author Share Posted March 7, 2011 Okay, I got it to work, finally. I kept messing around with quotes and single quotes and such and finally got the right combination. It might be that I finally added an insert for every column instead of just the ones I wanted to update, perhaps it was an issue with them requiring notnull and me not putting anything in (thus null?) Anyway: $query = "INSERT INTO ".TABLE_NAME." (handle,fName,lName,email,userLevel,loggedIn,password,banned,dateJoined,dateLastLogin,validated,validationCode) VALUES ('".$properties['username']."','0','0','".$properties['email']."','$userLevel',0,'".$properties['password']."',0,'$time',0,'$validated','$validationCode')"; Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/229822-not-sure-where-my-error-is-mysql-maybe/#findComment-1183832 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.