peter_anderson Posted November 19, 2009 Share Posted November 19, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/182175-solved-you-have-an-error-in-your-sql-syntax/ Share on other sites More sharing options...
cags Posted November 19, 2009 Share Posted November 19, 2009 I can't see anything obvious. What is the data type of the id column, if it's an integer try removing the double quotes your enclosing it in. Quote Link to comment https://forums.phpfreaks.com/topic/182175-solved-you-have-an-error-in-your-sql-syntax/#findComment-961197 Share on other sites More sharing options...
rajivgonsalves Posted November 19, 2009 Share Posted November 19, 2009 this description="'.$data['description'].'", WHERE id="'.$data['forumid'].'"'; should be description="'.$data['description'].'" WHERE id="'.$data['forumid'].'"'; there was a "," before where Quote Link to comment https://forums.phpfreaks.com/topic/182175-solved-you-have-an-error-in-your-sql-syntax/#findComment-961199 Share on other sites More sharing options...
premiso Posted November 19, 2009 Share Posted November 19, 2009 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) Quote Link to comment https://forums.phpfreaks.com/topic/182175-solved-you-have-an-error-in-your-sql-syntax/#findComment-961201 Share on other sites More sharing options...
rajivgonsalves Posted November 19, 2009 Share Posted November 19, 2009 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']); Quote Link to comment https://forums.phpfreaks.com/topic/182175-solved-you-have-an-error-in-your-sql-syntax/#findComment-961206 Share on other sites More sharing options...
peter_anderson Posted November 19, 2009 Author Share Posted November 19, 2009 Wow, that was a simple fix. Thanks for all your help Quote Link to comment https://forums.phpfreaks.com/topic/182175-solved-you-have-an-error-in-your-sql-syntax/#findComment-961208 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.