Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/229822-not-sure-where-my-error-is-mysql-maybe/
Share on other sites

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')";
  

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')";
?> 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.