Jump to content

[SOLVED] MySQL insert query error?


mrhobbz

Recommended Posts

I'm trying to run this query:

$sql = "INSERT INTO i_usr (NULL, usrname, usrpass, usremail, usrhandle) VALUES (NULL, '$username, '$password, '$email', '$handle')";	

 

This is the error it spits out: 

Error : MySQL - Database Query

 

[1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL usrname usrpass usremail usrhandle VALUES test 098f6bcd4621d373cade4e832627' at line 1

 

 

Any ideas?

Link to comment
Share on other sites

Tried that, still nothing..

 

I'm passing it through this function:

public function query($sql) {
$sql = $this->clean_sql($sql);
$this->act = @mysql_query($sql, $this->con);

			if(!$this->act) {
				$this->err('MySQL', 'Database Query');
			}
			$this->affected_rows = mysql_affected_rows($this->con);	
}

and it shoots the sql statement through this function:

public function clean_sql($string) {
$string = ereg_replace("[\'\")(;|`,]", "", $string);
$string = mysql_real_escape_string(trim($string), $this->con);
return $string;
}

Link to comment
Share on other sites

Good eye, I tried that and i get:

 

Error : MySQL - Database Query

 

[1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'usrname usrpass usremail usrhandle VALUES test 098f6bcd4621d373cade4e832627b4f6 ' at line 1

Link to comment
Share on other sites

You have no commas separating your fields/values. This is because your clean_sql function removes comma's (and other required characters) from your query. This is the offending line:

$string = ereg_replace("[\'\")(;|`,]", "", $string);

I'd recommend you remove that line.

 

Link to comment
Share on other sites

Tried that, just using the mysql_real_escape_string and I get:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'test\', \'098f6bcd4621d373cade4e832627b4f6\', \'test@gmail.com\', \'test\')' at line 1

Link to comment
Share on other sites

You need to rethink how you escape data in your query. Currently you're passing the whole query to your query() method, which in turn passes the query to clean_sql() method which will escape all quotes in your query and not your queries values.

 

You should escape all data before constructing the query itself.

 

 

Link to comment
Share on other sites

Then why are you passing the whole query to your clean_sql() method? Change your query() method to

public function query($sql) {

$this->act = @mysql_query($sql, $this->con);

			if(!$this->act) {
				$this->err('MySQL', 'Database Query');
			}
			$this->affected_rows = mysql_affected_rows($this->con);	
}

Link to comment
Share on other sites

Look's like it is still seeing exta " ' ".  try debugging by doing one item at a time to see what value is caussing the burp.

 

$sql = "INSERT INTO i_usr (usrname) VALUES ('$username')"; 

 

then

$sql = "INSERT INTO i_usr (usrpass) VALUES ('$password)"; 

 

if no problems there, you'r varibale as fine.  If you do have a problem, you have to look at what your variables are.  You might also want to try "$username" double quotes.

 

 

 

 

 

 

 

Link to comment
Share on other sites

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.