MySQL Error when INPUTTING into a table.

Status
Not open for further replies.

Joshie

WebHost Founder
May 29, 2015
143
20
Hiya,
I ain't too good with MySQL
So I need a little bit of help here.

I get the following error when attempting to use the input forms to upload a news article to a panel (not a retro cms or anything, fansite panel)
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 '2', '1551388848')' at line 1

The Code:
Code:
if( $_POST['submit'] ) {

                try {
                    
                    $title   = $core->clean( $_POST['title'] );
                    $cat     = $core->clean( $_POST['category'] );
                    $article = $core->clean( $_POST['article'] );
                                        $desc = $core->clean( $_POST['desc'] );

                    $time    = time();

                    if( !$title or !$article ) {

                        throw new Exception( "All fields are required." );

                    }
                    else {
                        
                        if( $editid ) {
                            
                            $db->query( "UPDATE news SET title = '{$title}', category = '{$cat}', article = '{$article}', desc = '{$desc}' WHERE id = '{$editid}'");
                            
                        }
                        else {
                        
                            $db->query( "INSERT INTO news VALUES ('0', '{$cat}', '{$title}', '{$article}', {$desc}', '{$user->data['id']}', '{$time}');" );
                        
                        }

                        echo "<div class=\"mws-form-message success\">Success!<ul><li>Article successfully added!</li></ul></div>";

                    }

                }
                catch( Exception $e ) {

                    echo "<div class=\"mws-form-message error\">";
                    echo "Error";
                    echo "<ul><li>";
                    echo $e->getMessage();
                    echo "</li></ul></div>";

                }

            }

        ?>

Any help is appreciated.
 

Joshie

WebHost Founder
May 29, 2015
143
20
Use graves

Code:
UPDATE news SET `title` = 'TITLE', `category` = 'CATEGORY', `article` = 'ARTICLE', `desc` = 'DESC' WHERE `id` = 'ID'
Still getting the same error pal.
Post automatically merged:

I know that the "2" is the USER ID and the long number is the STAMP, both variables exist in the MySQL table.
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,482
1,482
Did you do it for the other query too?

Code:
UPDATE news SET `title` = '$title',
`category` = '$cat',
`article` = '$article',
`desc` = '$desc'
WHERE `id` = '$editid'

Also, you don't need the brackets
 
Status
Not open for further replies.

Users who are viewing this thread

Top