0

I've written this mysql query, but for some weird reason it's working in phpmyadmin. When I run this query in php it doesn't work.

mysql

$sql = "INSERT INTO msw_posts (user_id, user_name, title, vak, richting, type, post_date, points, views, likes, dislikes, year, keywords, discription)
VALUES ('1', 'test user', 'test', 'bio', 'aso', 'cursus', '2016-05-04', '0', '0', '0', '0', '3', 'test', 'discr')";

PHP

                    if (mysqli_query($dbConn, $sql)) {
                        echo "New record created successfully";
                        //uploaden en checken of upload in orde is
                        if(move_uploaded_file($_FILES['bestand']['tmp_name'], $dir.$file)){
                            header("Location: uploaden.php?type=ok");
                        }else{
                            header("Location: uploaden.php?type=failed_uploading");
                        }
                    } else {
                        echo "Error: " . $sql . "<br>" . mysqli_error($conn);
                    }

Thanks for your advice or help!!

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
DW_
  • 104
  • 1
  • 11
  • 3
    `type` is a [MySQL reserved word](https://dev.mysql.com/doc/refman/5.6/en/keywords.html) and can't be used for a table or column name if it isn't enclosed in backticks (`\``); `year` is a mysql reserved word, likewise – Mark Baker May 05 '16 at 07:08
  • Try writing your field names with `\`` (It is the symbol before Num 1 key) Like: `INSERT INTO msw_posts (\`user_id\`, \`user_name\`, ...` Sometimes it confuses with Existing Command. – TipuZaynSultan May 05 '16 at 07:10
  • @markBaker thanks for your help!! – DW_ May 05 '16 at 07:12
  • Possible duplicate of [Syntax error due to using a reserved word as a table or column name in MySQL](http://stackoverflow.com/questions/23446377/syntax-error-due-to-using-a-reserved-word-as-a-table-or-column-name-in-mysql) – andrewsi May 13 '16 at 01:24

1 Answers1

1

use back-quotes("`") on your field name as you have used many of the mysql reserve keyword in your field name

Dipanwita Kundu
  • 1,637
  • 1
  • 9
  • 14