Jump to content

Recommended Posts

Hi,

 

I'm getting the error "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 'WHERE `id`="9"' at line 2" with my query.

 

Here is the code:

public function doEditCat($data = array()){
	if($_SESSION['loggedin'] != 'yes') {
		return '<h2>Error!</h2>You must be logged in before you can access this feature';
	}
	# Connect To Database
	# Attempt Connection
	$sql = new mysqli(db::$config['host'], db::$config['user'], db::$config['pass'], db::$config['db']);
	# Error Checking
	if (mysqli_connect_errno()) {
	    printf("Connect failed: %s\n", mysqli_connect_error());
    	exit();
	}
	# Check we've submitted something
	if($data['forumid'] == ''){
	return '<h2>Error!</h2><p>Some data was not added while editing your forum. The forum ID was not specified!</p>';
	}
	# Tell us if we're a sub forum or not....
	if($data['subforum']=='Yes'){
		$subforum = '1';
	}else{
		$subforum = '0';
	}
	# Query
	$query = 'UPDATE `categories` SET subforum="'.$subforum.'", parent="'.$data['parent'].'", title="'.$data['title'].'", 
	description="'.$data['description'].'", WHERE id="'.$data['forumid'].'"';
	if (!$sql->query($query)) {
		printf($sql->error);
	}
	# Return!
	return '<h2>Success!</h2><p>Forum successfully updated!</p>';
}

 

Can anyone see what's wrong? I can't see any problems.

description="'.$data['description'].'", WHERE id="'.$data['forumid'].'"';

 

There is a , before the WHERE. As well as you have your quotations mixed up, singlequotes surround the sql data...

 

description='".$data['description']."' WHERE id='".$data['forumid']."'";

 

You will have to fix that in the other section of the query as well (the quote part).

 

EDIT:

Moving to the proper board (MySQL Help)

Yeah its kinda quite hard to read, you could use sprintf for better readability

 

$query = sprintf("UPDATE `categories` SET subforum='%s', parent='%s', title='%s',
      description='%s' WHERE id='%s'", $subforum, $data['parent'], $data['title'], $data['description'], $data['forumid']);

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.