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!!

4
  • 3
    type is a MySQL reserved word 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 Commented May 5, 2016 at 7: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. Commented May 5, 2016 at 7:10
  • @markBaker thanks for your help!! Commented May 5, 2016 at 7:12
  • Possible duplicate of Syntax error due to using a reserved word as a table or column name in MySQL Commented May 13, 2016 at 1:24

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.