tags:

views:

51

answers:

3

i have two textfield..one for show datepicker and another one for time.. but i want after input to DB they can combine become one field inside DB..so that i set field type as datetime...

to make them combine..i'm doing some manipulation inside process.php page..this is my code:

$sql = "INSERT INTO inspection_report ";
$sql.= "(Model,Serial_number,Line, Shift,Inspection_datetime,Range_sampling,Packing, ";
$sql.= "Accesories,Appearance,Tuner,General_operation,Remark, ";
$sql.= "NIK,Time_inspection) ";
$sql.= "VALUES ('";
$sql.= $Model."','".$Serial_number."','".$Line."','".$Shift."','".STR_TO_DATE("'".postVar('insp_date')." ".postVar('time')."'","%M/%d/%Y/ %T")."','".$Range_sampling$
$sql.= $Accesories."','".$Appearance."','".$Tuner."','".$General_operation."','".$Remark."','";
$sql.= $NIK."','".$Time_inspection."')";

but it show error "PHP Fatal error: Call to undefined function STR_To_DATE()"..what must i do to make them can combine without error?

+3  A: 

The STR_TO_DATE() method is a MYSQL method, so it need to be part of your query string, otherwise PHP tries to execute it. Just move the quotes around the STR_TO_DATE and its closing ) to include it into the string.

... $Shift."','STR_TO_DATE('".postVar('insp_date')." ".postVar('time')."'","%M/%d/%Y/ %T)','".$Range_sampling ...

Hope that helps you get past that error.

Steve
oh no..it become 500 internal server error..
klox
There may be other problems in the source, have a dig around, also check your apache logs. Also you should `echo` the final SQL statement to make sure it is correctly formed as you have alot going on there.
Steve
yupz..after dig around i have a conclusion..
klox
A: 

i change date format at jquery:

<scrip>
 $(function() {
               $("#datepicker").datepicker({ dateFormat:'yy-mm-dd'});
               });
</script>

and change this part:

 $sql.= $Model."','".$Serial_number."', '".$Line."','".$Shift."','".postVar('insp_date')." ".postVar('time')."','".$Range_sampling."','".$Packing."','";
klox
A: 

use strtotime() check http://in2.php.net/manual/en/function.strtotime.php

chinni776
thank's 4 your answer..my program can work normally after i change some code...look at my answer..
klox
@klox as im new i dont know where to look for the answer
chinni776
@klox sorry i dint see the abovanswer
chinni776
@chinna:in my question page..there are mention 3 answer..from steve,u, and i..that's my answer..
klox