Jump to content

[SOLVED] Problem with inserting date


nati

Recommended Posts

Hello everybody,

 

I hope this is right place for the question I need to ask.

 

I have php 5.2.6 and MySQL 5.0.51b-community-nt.

 

The problem is next: I have an insert statment on my php page and one of columns I have to insert is current date.

 

Type of that column in database is DATE.

 

As I have read, database format of column type DATE is 'YYYY-MM-DD', so, I used php function:

date('Y-m-d') to get proper format, but I am getting next 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 ' '', 2008-11-09)' at line 24".

 

Where is my mistake, can anyone help me please?

 

 

Tnx in advance!

Nati

Link to comment
Share on other sites

Well, I used single quotes, and I will provide my code so you can see clearly how it looks like:

 

$datum=date('Y-m-d');

$query1 = "insert into registrovani_korisnici

            (id,

            username,

            password,

            ime,

            prezime,

            datum_otvaranja_naloga)

            values

            ('',

            '".$korime."',

            '".md5($loz)."',

            '".$ime."',

            '".$prez."',

              '".$datum."')";

 

And this code produces the error I told about.

 

If I change my code as you suggested:

 

$query1 = "insert into registrovani_korisnici

            (id,

            username,

            password,

            ime,

            prezime,

            datum_otvaranja_naloga)

            values

            ('',

            '".$korime."',

            '".md5($loz)."',

            '".$ime."',

            '".$prez."',

              curdate())";

 

I am again getting 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 ' '', CURDATE())' at line 24"

 

Am I doing something wrong?

 

 

Regards,

Nati

Link to comment
Share on other sites

Hey, it is solved!

 

prez is mandatory data, as some other fields, and before this query I had some check of input fields which was skipped because of my typing mistake  :-X.

 

I corrected it and everything works fine now.

 

Tnx a lot,

Nati

Link to comment
Share on other sites

And here's mu suggestion for your query. Less quotes => lower possibility of mistake. And 'id' can be ommited altogether, as you're entering an empty value.

$query1 = "INSERT INTO registrovani_korisnici (
             username,
             password,
             ime,
             prezime,
             datum_otvaranja_naloga
             ) VALUES (
             '$korime',
             MD5($loz),
             '$ime',
             '$prez',
             CURDATE())";

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.