Hi,
I use PDO for the first time.I succeeded to make a connection and to read a table.
But when I try to insert a record it fails. I looked at many tutorials, and thought I found the right, but it goes through the script without errors, doing nothing. Here is the code I used. The variables I set before, they have values, the connection is made and tested.
There’s nothing wrong on the face of it, presuming that you have those valid column names in your table, and that the data that you are trying to insert is valid. The colons are optional (which I didn’t realise until recently) but I have them in my code and they don’t stop anything working.
Also note that if $now is just the current date/time, you can save a bit of time by setting the default value for that column to be current_timestamp (or something like that, phpmyadmin will show you) and just not mention it in your insert query. It will then default to current date/time.
I set timestamp for mdate, that is ok in phpmyadmin.
I also made parent default 0, so the only variable reamaining is uname, which is “Dag”, also shows me with
echo $uname;
Still it does not make any entry. In front of this routine I have a test to read the table, so that I know the connection is established, The routine now look like this:
Any error before could make the script stop working. But there’s a syntax error in your new code because of a missing bracket in the end. Are you sure you implemented all the necessary error reporting settings? You should start here
I will try to make the connection exactly as in the tutorial.
But I counted the brackets, seems right to me, if I add one more the script is false.
EDIT:
Syntax error or access violation: 1064 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
Where does this come from? Seems like opening connection. I used “localhost” as host, also tried “127.0.0.1” as in the tutorial.
Somehing wrong there?
I had a linebreak in mine, but I changed that. Didn’t change the result.
The problem right now seems to be: PDO has a problem with MySQL, or the version.
But first after I activated the error trap. Before I did that, I could use the connection to read, at least. You see me confused,
That’s right. But if I add a right bracket the script fails. Means the outputs I have as control disappear and an entry it still doesn’t make. How many traps more…
Perhaps I should make a break. I feel more than silly right now
They kind of signify “what is between these are a thing” (OK, I realize that doesn’t say it very well. Anyway … )
Code can get messy when there are a lot of them especially when they are nested. I’ll try indenting again. After a “start” I’ll indent the next line until there is a “close” which I’ll put at the same indentation as the previous “start”
I tried this, also copied what you wrote inserted that in the script. and the script fails. I I have no idea why, because I see you are right, and it is not logical at all. I will,as I said make a break, breatht through and write it all new.