I'm having a really weird issue as well as a stressful time trying to figure this out.
Using a form, I was trying to insert data into my database. The initial SQL query had variables for values, but it didn't work. After trying a few things and using mysqli_error I wasn't able to find the problem. I then replaced all the variables with strings, still, my data does not insert.
I've tried the below code nested amongst other bits of PHP, doesn't work. I tried it on a different page, didn't work. So I stripped everything and left just the mysql_connect link and the mysqli_query and it still will not insert.
The error mysqli_error reports is ALWAYS, even if there is nothing what so ever related to mysql (tried it nested further down the page, and on different pages, and on it's own page) on line 2, the following: 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 '' at line 2
and I just cannot make sense of it.
My code below is as follows:
$link = mysqli_connect("host", "username", "password", "database") or die("cannot connect"));
$try = mysqli_query($link,"INSERT INTO troubleshooting_files (`title`, `asset`, `image`, `category`, `file`)
VALUES ('title', 'asset', 'image', 'cat', 'file'");
//$try = mysqli_query($link,"INSERT INTO troubleshooting_users (`name`)
//VALUES ('title'");
if($try === false){
echo 'error - ';
echo mysqli_error($link);
} else{
echo 'all good';
}
I have tried entering just one field, I tried without the `s in the field names, I tried a different table name and it doesn't work. phpMyAdmin inserts data into the tables fine. I also have PHP code in a different directory on the server that inserts data fine into this database, although that code still uses the deprecated mysql_query at the minute. I also have code that inserts rows fine on this server into a different database. I assume the database must be fine if PMA can insert data okay, and elsewhere in my script, other mysqli_query's work fine as I can fetch objects and update tables fine.
I really don't know what else to try. Any ideas would be great.
EDIT: Thank you all, it was the missing ) after the values! If only mysqli_error could have at least hinted towards this rather than giving me nothing of use.