×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Insert Varible Date (HTML/PHP) In DBF File
2

Insert Varible Date (HTML/PHP) In DBF File

Insert Varible Date (HTML/PHP) In DBF File

(OP)
I made an HTML and PHP application using a DBF database via an ODBC connection, as follows:

FOXPRO DATABASE (MASTER.DBF) :
Employee Character 50
Datebirth Date 8

CODE HTML :
Date Of Birth : <input TYPE="DATE" NAME="VARDATE">
I fill data/variable => 12-08-1970

CODE PHP :
//convert variable date//
$PHPDATE = $_POST['VARDATE']; => result : 1970-08-12
$FOXDATE = DATE('d-m-Y',strtotime($PHPDATE)); => result : 12-08-1970

//insert variable date//
$CON=ODBC_CONNECT('DATABASE','','');
$SQL="INSERT INTO MASTER (DATEBIRTH) VALUES ('$FOXDATE')";
$SQL_RESULT=ODBC_PREPARE($CON,$SQL);
ODBC_EXECUTE($SQL_RESULT);
ODBC_CLOSE($CON);

There is an error message when saving the PHP variable "$FOXDATE" into field "DATEBIRTH" of MASTER.DBF :
Warning: odbc_execute() [function.odbc-execute]: SQL error: [Microsoft][ODBC Visual FoxPro Driver]Data type mismatch., SQL state 22005 in SQLExecute in C:\xampp\htdocs\SAVE.PHP on line 145

Please explain and help with the error message above

Thank you for the help

RE: Insert Varible Date (HTML/PHP) In DBF File

PHP DATE() function creates a string, your DBF field is a Date. In VFP SQL unlike other SQL dialects there is no implicit string to date type conversion.

One way to make the conversion would be CTOD:

CODE

$SQL="INSERT INTO MASTER (DATEBIRTH) VALUES (CTOD('$FOXDATE'))"; 

CTOD depends on VFP settings both in the day/month or month/day order and the separator character, so better is to use:

CODE

$FOXDATE = DATE('Y-m-d',strtotime($PHPDATE));
...
$SQL="INSERT INTO MASTER (DATEBIRTH) VALUES ({^$FOXDATE})"; 

The third option would be using a parameterized query and a date parameter.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: Insert Varible Date (HTML/PHP) In DBF File

(OP)
Thank you so much for your help Bro Olaf,
It solved with option :

CODE :
$FOXDATE = DATE('Y-m-d',strtotime($PHPDATE));
...
$SQL="INSERT INTO MASTER (DATEBIRTH) VALUES ({^$FOXDATE})";

Regards,

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close