Thursday, 12 October 2017

php - Error with my SQL syntax? Can't seem to find it

I might be going crazy, but I swear the code below was
working yesterday and now it's not working. I noticed it wasn't inserting into database
and I'm getting the error:



You
have an error in your SQL syntax; check the manual that corresponds
to your
MariaDB server version for the right syntax to use near 's',
'39866',
'9780448438047', 'Miss Spider's Sunny Patch Friends: Fun with Bounc' at line
1


Here is the query
below. I know I'm not using escape strings/prepared statements, but that is because this
is just a localhost number
cruncher.



$insert =
mysqli_query($connect, "INSERT INTO books

(subject, booknum,
isbn, title, author, publisher, year,
format, mark, hurt, pubprice, srp,
avail) VALUES
('$subject', '$booknumber', '$isbn', '$title', '$author',

'$publisher', '$year', '$format', '$mark', '$hurt',
'$pubprice',
'$srp', '$avail')") or
die(mysqli_error($connect));


It
seems like even commenting out that line and just
doing:



$insert1 =
mysqli_query($connect, "INSERT INTO books (subject) VALUES


('$subject')") or
die(mysqli_error($connect));


Also
leads to an error. I'm guessing this means the error is actually located in my db
connection itself? I'm
using:



$connect
= mysqli_connect("localhost", "root", "",
"wholesale");
if(mysqli_connect_errno()) {
echo "Failed to connect.
Error: " .
mysqli_connect_error();
}



Which
is included at the top of the
page:



include
'db.php';


But like I
said, this application was working last night. All that has changed since then is I
turned off and on my computer and restarted xampp, as far as I can
remember.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...