If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Date Format

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-09-10, 09:46
don_log don_log is offline
Registered User
 
Join Date: Jun 2008
Location: pakistan
Posts: 109
Date Format

I want to insert in a value using php but some problem
in it's sql query

insert into school.std_info values('7','std','sd','2323','mj','234','sadf23',D ATE_FORMAT('17-11-1990','%d-%m-%Y'),'male','234234','234234','2010-06-09','22','10')

this is the mysql query giving me error when i direct put in mysql
PHP Code:

#1136 - Column count doesn't match value count at row 1

INSERT INTO school.std_info
VALUES 
(
'7''std''sd''2323''mj''234''sadf23'DATE_FORMAT'17-11-1990''%d-%m-%Y' ) , 'male''234234''234234''2010-06-09''22''10'

PHP Code:
stnd_code int(11)   
  
stnd_fcode int(11)                
  
stnd_name varchar(50
  
stnd_fname varchar(50)
  
stnd_fnic varchar(25)
  
stnd_mname varchar(50)
  
stnd_mnic varchar(25
  
stnd_add varchar(100
  
stnd_dob date
  stnd_gender varchar
(6)
  
stnd_ph int(11)                
  
stnd_mob int(11
 
stnd_jdate date 
  stnd_fees int
(5)  
  
stnd_class varchar(10
table structure
Reply With Quote
  #2 (permalink)  
Old 06-09-10, 11:04
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
Quote:
Originally Posted by don_log View Post
but some problem
do you see what the problem is? you have 15 columns in the table, but you are supplying only 14 values, therefore the error is "Column count doesn't match value count"

by the way, that DATE_FORMAT function call will ~not~ do what you expect -- use the STR_TO_DATE function instead
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 06-09-10, 12:25
don_log don_log is offline
Registered User
 
Join Date: Jun 2008
Location: pakistan
Posts: 109
it insert this function date in null

NULL show in row

when i insert and browse the table
Reply With Quote
  #4 (permalink)  
Old 06-09-10, 13:33
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
mysql expects dates in ISO format YYYY/MM/DD, or YYYY-MM-DD or some other year month day styling
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #5 (permalink)  
Old 06-09-10, 14:32
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
which is what the STR_TO_DATE function accomplishes

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 06-11-10, 14:05
saviola saviola is offline
Registered User
 
Join Date: Jun 2010
Posts: 6
The default way to store a date in MySQL is with the type DATE. Below is the proper format of a DATE.
- YYYY-MM-DD
- Date Range: 1000-01-01 to 9999-12-31

Quote:
INSERT INTO dateplayground (dp_name, dp_date) VALUES ('DATE: Manual Date', '2020-2-14')
Below is a quick script that will spit out the MySQL table dateplayground in HTML.
PHP Code:
<?php
$query 
"SELECT * FROM dateplayground";
$result mysql_query($query) or die(mysql_error());

echo 
"<table border='1'><tr>";
for(
$i 0$i mysql_num_fields($result); $i++){
    echo 
"<th>".mysql_field_name($result$i)."</th>";
}
echo 
"</tr>";
while(
$row mysql_fetch_array($result)){
    echo 
"<tr>";
    for(
$i 0$i mysql_num_fields($result); $i++){
        echo 
"<td>"$row[$i] ."</td>";
    }
    echo 
"</tr>";
}

echo 
"</table>";

?>
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On