Jump to content

Problems inserting data into a database


eMonk

Recommended Posts

I have a mysql table with about 20 columns. The 2 giving me problems are:

 

age tinyint(2) unsigned,

weight tinyint(3) unsigned,

 

For some reason these 2 fields have to be entered in when submitting from a HTML form or I get the following error:

 

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 20

 

I tried changing these 2 fields to varchar like the rest of the columns but phpmyadmin is giving me an error. Can anyone shed some light on this? I would like the user to be able to leave these 2 fields blank if they want to.

Link to comment
Share on other sites

Good idea Maq, I could just run a separate query when the user fills these 2 fields out but there must be a way to do this in 1 query?

 

All columns in the table are NULL by default.

 

BTW ManiacDan: I can leave all the fields blank just not these 2 for some reason.

Link to comment
Share on other sites

Good idea Maq, I could just run a separate query when the user fills these 2 fields out but there must be a way to do this in 1 query?

 

All columns in the table are NULL by default.

 

BTW ManiacDan: I can leave all the fields blank just not these 2 for some reason.

Because those fields are numbers, and if you leave a number blank you end up with an empty field just like the one in the error I've already pointed out.

 

Hello!  Look!

 

'' <-- something

  <-- nothing

 

You can't have nothing between two commas.

 

For your string fields, what you're thinking of as "nothing" is actually the string ''

 

For your numeric fields, "nothing" is actually nothing and that's illegal in SQL

 

Make it something.

Link to comment
Share on other sites

Oh I see, thanks for clearing that up ManiacDan!

 

I tried changing these 2 tinyint fields into varchar but get the following error in phpmyadmin:

 

Error

SQL query:

 

ALTER TABLE  `model` CHANGE  `weight`  `weight` VARCHAR( 3 ) UNSIGNED NULL DEFAULT NULL

 

MySQL said:

 

#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 'UNSIGNED NULL DEFAULT NULL' at line 1

 

Why is there a syntax error when I'm using phpmyadmin. See anything wrong with this sql syntax?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.