![]() |
|
|
#1 |
|
Junior Member
Join Date: Jan 2005
Posts: 9
|
Hi guys
I'm having trouble writing to a mysql table. I've created php scripts to insert records into one table of the mysql database, which works fine. However, I have set up a second table, using the exact same php script (except for obvious changes ie. table and fields) and for some unknown reason, i look in mysql-front only to find that the record has not been inserted. I've tried everything, from dropping the table, and re-coding it, but to no avail. There's way too much code for me to paste, but if you have any ideas, please reply ASAP. Thanks heaps, ZS |
|
|
|
|
|
#2 |
|
Member
Join Date: Nov 2004
Posts: 31
|
Re: php - mysql problem
Have the PHP script echo the INSERT statement instead. Copy and paste the statement into MySQL directly and see what MySQL tells you is wrong. Are you checking the return value of mysql_query() in your script?
|
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jan 2005
Posts: 9
|
Re: php - mysql problem
Yes, I am checking the value of mysql_query() in my script, as follows;
$query = "insert into table_name values ('".$variable."', '".$variable."', '".$variable."')"; $result = mysql_query($query); if ($result) echo mysql_affected_rows().' record(s) inserted into database.'; Thanks for your reply, codenode, I'll keep testing... |
|
|
|
|
|
#4 |
|
Junior Member
Join Date: Jan 2005
Posts: 9
|
Re: php - mysql problem
Sorted the problem, I didn't think it would work, but it did. I made a simple change to my query line;
$query = "insert into table_name (field1, field2, field3) values ('".$variable1."', '".$variable2."', '".$variable3."')"; Thanks for your advice anyways, codenode. |
|
|
|
|
|
#5 |
|
Member
Join Date: Nov 2004
Posts: 31
|
Re: php - mysql problem
Excellent. Do you know why an explicit list of fields is needed?
|
|
|
|
|
|
#6 |
|
Junior Member
Join Date: Jan 2005
Posts: 9
|
Re: php - mysql problem
nope, my php code is the same for writing to both tables. Both tables are very similar, if not identical in structure. However, php writes to the first table without the explicit mysql field declaration, but for some reason, I need to declare the fields when writing to the second table...
|
|
|
|
|
|
#7 |
|
Member
Join Date: Nov 2004
Posts: 31
|
Re: php - mysql problem
The shorthand "INSERT INTO table VALUES (1, 2, 3);" only works if table has exactly 3 columns. If you have to explicity list the columns for your 2nd table it must have more or less colums than your first table.
|
|
|
|
|
|
#8 |
|
Junior Member
Join Date: Jan 2005
Posts: 9
|
Re: php - mysql problem
Doesn't matter now, I've fixed it. Thanks heaps for your advice! I appreciate it.
But now I'm having another problem, I'm attempting to write an integer to the table from an html form, but for some reason it keeps recording a different constant integer. a basic description: 1. the input field on the html form is called: name="cardNumber" 2. i successfully echo $cardNumber back to the user on a php confirmation page. 3. upon pressing submit, $cardNumber is written to the field cardNumber in the mysql database, but instead of being the value inserted by the user, it comes up with '2147483647' which was the first value i entered as test data a few days ago... why would it be storing this number as default? |
|
|
|
|
|
#9 |
|
Junior Member
Join Date: Jan 2005
Posts: 9
|
Re: php - mysql problem
Fixed that one too. I'll shut up now :P
|
|
|
|
|
|
#10 |
|
Junior Member
Join Date: Jan 2005
Posts: 9
|
Re: php - mysql problem
what the?? the above "default value" problem seems to have returned after the system was working fine, and I'm absolutely lost as to why this 2147483647 keeps appearing. I've checked to see that my columns are in the right order, but this still happens...
Any advice? |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using PHP and MySQL to build a dynamic website | mchu | PHP | 0 | 09-15-2004 12:49 AM |
| Import Access, Excel and data of other formats to MySQL by Navicat | NavicatGuy | Articles | 0 | 08-17-2004 01:08 AM |
| 3.2 Entering Queries | Administrator | Documentation | 0 | 06-09-2004 02:58 AM |
| 1.2.2 The Main Features of MySQL | Administrator | Documentation | 0 | 06-08-2004 01:55 AM |
| 1.2 Overview of the MySQL Database Management System | Administrator | Documentation | 0 | 06-07-2004 10:11 PM |