Thread: [RESOLVED] mysql_query: INSERT does not insert anything at all...
Started 4 weeks, 1 day ago by Copenhagener
Hi there,
I am able to read from my database table, but I am not able to write .
As far as I can see, my code is correct, and my database table has been set up correctly. However, when I test my script, nothing is inserted into my table. I have no idea what is wrong.
Can anyone figure out what is missing or incorrect in my SQL query?
My script is as follows:
...
I now suspect that there is a problem with the way I handle date() and time() and the way I attempt to store these values. It seems that a value based on the time() function becomes empty and returns an error when trying to insert it into a NOT NULL field.
Don't laugh if the following is complete nonsense; at least then that is where my error is to be found:
PHP Code:...
While testing some example results, I get:
$dob >> 19900304 (correct; 4 March 1990)
$subscr_date >> 1257584137 (something is definitely wrong here)
$subscr_time >> NULL
I tried to fix the script for the values $subscr_date and $subscr_time.
Now, $subscr_time is no longer NULL, so that was not the only problem. The values become 10 digits long, while the coloumns are INT (8) each. Perhaps this is generating the syntax error now, and further work with thos two values are required.
My first thought is that those fields should be DATE or TIME column types, not integers. If so, then the values you would insert would be strings ('2009-02-31' or '12:51') instead of being cast to integers. (In fact, I would just create a single DATETIME column for subscription date/time.)
Anyway, if you want to continue with the current scheme, use date () instead of time () to get the ...
My first thought is that those fields should be DATE or TIME column types, not integers. If so, then the values you would insert would be strings ('2009-02-31' or '12:51') instead of being cast to integers. (In fact, I would just create a single DATETIME column for subscription date/time.)
Anyway, if you want to continue with the current scheme, use date () instead of time () to get ...
Thanks for your inputs, MotDog.
I rewrote my script with regards to the date and time, and now at least I get the right values:
PHP Code:
$time_array = getdate ();
foreach( $time_array as $item => $val ) {
$item = $val ;
}
$thisYear = $time_array [ year ];
$thisMonth = $time_array [ mon...
Wow! Thanks, Lars - that was really the KEY to the whole problem!
Honestly, I would never had realised that I was using a reserved term.
Here is my final script and query which WORKS:
PHP Code:
include( "archive/file.inc" );
$connection = mysql_connect ( $host , $account , $password )
or die( ...
An important note to the solution: I also found a related mistake, that I used $password for both the MySQL login and for the user password. Once the script and query worked, I wondered why it stored the same password every time, although I tested with different password - and it was not stored as a 32-digit hex, either. Then I finally noticed that it was my own MySQL password, and when I looked at my script again, I knew I had to rename the...
My first thought is that those fields should be DATE or TIME column types, not integers. If so, then the values you would insert would be strings ('2009-02-31' or '12:51') instead of being cast to integers. (In fact, I would just create a single DATETIME column for subscription date/time.) Anyway, if you want to continue with the current scheme, use date () instead of time () to get the values for the current date/time.
Thread profile page for "[RESOLVED] mysql_query: INSERT does not insert anything at all..." on http://www.phpbuilder.com.
This report page is a snippet summary view from a single thread "[RESOLVED] mysql_query: INSERT does not insert anything at all...", located on the Message Board at http://www.phpbuilder.com.
This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity