Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

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: ...
Site: PHPBuilder.com  PHPBuilder.com - site profile
Forum: Newbies  Newbies - forum profile
Total authors: 3 authors
Total thread posts: 12 posts
Thread activity: no new posts during last week
Domain info for: phpbuilder.com

Other posts in this thread:

NogDog replied 4 weeks, 1 day ago
Anything in the PHP error log, in case display_errors is turned off in your config?

Copenhagener replied 4 weeks, 1 day ago
Rewrote the script to get some errors: PHP Code: include( "archive/file.inc" ); $connection = mysql_connect ( $host , $account , $password ) or die( "Error: " . mysql_error ()); $db = mysql_select_db ( $dbname , $connection ) or die( "Error :" . mysql_...

Copenhagener replied 4 weeks, 1 day ago
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:...

Copenhagener replied 4 weeks, 1 day ago
While testing some example results, I get: $dob >> 19900304 (correct; 4 March 1990) $subscr_date >> 1257584137 (something is definitely wrong here) $subscr_time >> NULL

Copenhagener replied 4 weeks, 1 day ago
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.

NogDog replied 4 weeks, 1 day ago
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 ...

NogDog replied 4 weeks, 1 day ago
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 ...

Copenhagener replied 4 weeks, 1 day ago
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...

Lars Berg replied 4 weeks, 1 day ago
key is a reserved word in Mysql. Rename column or escape it as `key`

Copenhagener replied 4 weeks, 1 day ago
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( ...

 

Top contributing authors

Name
Posts
Copenhagener
8
user's latest post:
[RESOLVED] mysql_query: INSERT...
Published (2009-11-07 11:26:00)
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...
NogDog
3
user's latest post:
[RESOLVED] mysql_query: INSERT...
Published (2009-11-07 07:26:00)
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.
Lars Berg
1
user's latest post:
[RESOLVED] mysql_query: INSERT...
Published (2009-11-07 09:28:00)
key is a reserved word in Mysql. Rename column or escape it as `key`

Related threads on "PHPBuilder.com":

Related threads on other sites:

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