MySqlTalk.com  

Go Back   MySqlTalk.com > MySQL > General
User Name
Password
FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
Thread Tools Search this Thread
Old 01-07-2005, 04:51 AM   #1
ZeroSignal
Junior Member
 
Join Date: Jan 2005
Posts: 9 ZeroSignal is on a distinguished road
Angry php - mysql problem

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
ZeroSignal is offline   Fork this post Reply With Quote
Old 01-08-2005, 03:58 AM   #2
codenode
Member
 
Join Date: Nov 2004
Posts: 31 codenode is on a distinguished road
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?
codenode is offline   Fork this post Reply With Quote
Old 01-09-2005, 12:13 AM   #3
ZeroSignal
Junior Member
 
Join Date: Jan 2005
Posts: 9 ZeroSignal is on a distinguished road
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...
ZeroSignal is offline   Fork this post Reply With Quote
Old 01-09-2005, 02:46 AM   #4
ZeroSignal
Junior Member
 
Join Date: Jan 2005
Posts: 9 ZeroSignal is on a distinguished road
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.
ZeroSignal is offline   Fork this post Reply With Quote
Old 01-09-2005, 03:19 AM   #5
codenode
Member
 
Join Date: Nov 2004
Posts: 31 codenode is on a distinguished road
Re: php - mysql problem

Excellent. Do you know why an explicit list of fields is needed?
codenode is offline   Fork this post Reply With Quote
Old 01-11-2005, 01:05 AM   #6
ZeroSignal
Junior Member
 
Join Date: Jan 2005
Posts: 9 ZeroSignal is on a distinguished road
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...
ZeroSignal is offline   Fork this post Reply With Quote
Old 01-11-2005, 11:44 PM   #7
codenode
Member
 
Join Date: Nov 2004
Posts: 31 codenode is on a distinguished road
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.
codenode is offline   Fork this post Reply With Quote
Old 01-12-2005, 04:46 AM   #8
ZeroSignal
Junior Member
 
Join Date: Jan 2005
Posts: 9 ZeroSignal is on a distinguished road
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?
ZeroSignal is offline   Fork this post Reply With Quote
Old 01-12-2005, 08:28 AM   #9
ZeroSignal
Junior Member
 
Join Date: Jan 2005
Posts: 9 ZeroSignal is on a distinguished road
Re: php - mysql problem

Fixed that one too. I'll shut up now :P
ZeroSignal is offline   Fork this post Reply With Quote
Old 01-25-2005, 03:41 AM   #10
ZeroSignal
Junior Member
 
Join Date: Jan 2005
Posts: 9 ZeroSignal is on a distinguished road
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?
ZeroSignal is offline   Fork this post Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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



All times are GMT -4. The time now is 08:51 PM.



Powered by: vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
Google
  Web http://www.mysqltalk.com
DISCLAIMERS:
1. We have no commercial interest in this site.
Banner Ads and Subscriptions will only be used to help pay for hosting and maintenance costs.
2. MySQLTalk.com is NOT affiliated with MySQL AB in any way.
3. MySQLTalk.com is NOT endorsed by MySQL AB in any way.
4. Please do not post any content that is harmful to MySQL or MySQL AB, meaning no misleading or obsolete information will be tolerated.
Well-founded constructive criticism meant to help the community is permitted.
5. This website is founded with the goal of improving the MySQL community.
We not only tolerate newbies, we encourage them.
Please do not ask newbies to "read the manual".