Data type mismatch in criteria expression using Access via ODBC

我怕爱的太早我们不能终老 提交于 2019-12-02 14:44:41

问题


$conn=odbc_connect('mobshopDB','','');
    if(!$conn){
        exit("Connection Failed: " . $conn);
    }
    $query="INSERT INTO users(uid,pass,fname,lname,pmm) VALUES('$username','$password','$fname','$lname',$pmm)";
    $rs=odbc_exec($conn,$query);

this query gives me this error

Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression., SQL state 22005 in SQLExecDirect in C:\Program Files\EasyPHP-5.3.6.0\www\mobshop\registered.php on line 39

..please suggest a solution

NOTE: pmm is a numeric field, thats why i haven't put it in quotes.


回答1:


"Data Type Mismatch" indicates that you are trying to pass in an incorrect data type in one of your variables for one of the fields listed in your first set of parenthesis.

Try writing $query to the screen using echo and then take that result and run it in your MS Access database query designer (assuming you have the MS Access software).




回答2:


Instead of This

$query="INSERT INTO users(uid,pass,fname,lname,pmm) VALUES('$username','$password','$fname','$lname',$pmm)";

Try This

$query="INSERT INTO users(uid,pass,fname,lname,pmm) VALUES('$username','$password','$fname','$lname','$pmm')";

You just forget single quote in $pmm field. Remember if you are using ODBC then be careful with datatype.

If the value will be an integer then do Type casting of value like this
$id = (int) $id;

If Datatype is not Integer then you must put single quotes



来源:https://stackoverflow.com/questions/5751823/data-type-mismatch-in-criteria-expression-using-access-via-odbc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!