I have jquery posting some data to this php file, the dev tools show the post data correctly. My insert delete statements execute correctly but this prepared statement does not. What have I done incorrectly.
Well, for starters I’d move your execute call outside of the if conditions, you should be checking $query->rowCount() = 1 . rowCount lets you see the number of rows affected by the query and since you seem to only ever need one it’s an easy place to check for an issue with the response, you could even throw in an else to respond to it being greater than 1.
Actually that looks like he’s trying to append the SQL to the query and mistook what the manner that’s done in was, instead replicating something that would be done inside a function, like echo, but didn’t realise echo is a function because it’s generally appended to non-parenthetically.
The way the code would read as written while executing would probably be something like this:
$sql = "UPDATE catalogues " “” =[error] "SET title = :title, manufacturer = :manufacturer, modified = :modified, category_id = :category_id, subcategory_id = :subcategory_id " . “” =[error] “WHERE id = :id”;
.= is the concatenation assignment operator in PHP, it essentially means append to end and it shorthand for $variable = $variable . “random string”; as . is the concatenation operator for strings. If you know javascript think of . as + and .= as Add to end of variable (string).
That all being said, you probably shouldn’t be attempting to concatenate the string unless it’s via conditionals or assigned variables. Since in this case the string in the variable $sql isn’t being modified by anything other than binds it should simply just be being assigned in one call to avoid issues like this (so like post #4 above).
I thought that too when I saw it, but I tested it and it actually still does concatenate the strings correctly (even though it’s not the usual way to do it).