msafvati Posted February 23, 2008 Share Posted February 23, 2008 hi i have a warning when i want to insert data to my DB:please guide me!! script is : <?php if (!strlen(trim($_GET['txt12']))) { echo "áØÝÇ äÇã ˜ÇÑÈÑí ÎæÏ ÑÇ æÇÑÏ äãÇííÏ"; die(); } $connectionstring = odbc_connect("User", "", ""); $query ="insert into tblRegCo values("; $query = $query."'".$_GET['txt1']."',"; $query = $query."'".$_GET['txt2']."',"; $query = $query."'".$_GET['txt3']."',"; $query = $query."'".$_GET['txt4']."',"; $query = $query."'".$_GET['txt5']."',"; $query = $query."'".$_GET['txt6']."',"; $query = $query."'".$_GET['txt7']."',"; $query = $query."'".$_GET['txt8']."',"; $query = $query."'".$_GET['txt9']."',"; $query = $query."'".$_GET['txt10']."',"; $query = $query."'".$_GET['txt11']."',"; $query = $query."'".$_GET['txt12']."',"; $query = $query."'".$_GET['txt13']."')"; $result = odbc_do($connectionstring,$query); echo "ÔãÇ ÈÇ ãæÝÞíÊ ÏÑ ÓíÓÊã ßÇÑíÇÈí ßÔæÑí ËÈÊ ÔÏíÏ " ; odbc_close($connectionstring); ?> warning is : Warning: odbc_do() [function.odbc-do]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression., SQL state 22005 in SQLExecDirect in D:\MAS\Prj2\Local path\MASRegCodCo\RegCo.php on line 262 thank u Link to comment https://forums.phpfreaks.com/topic/92556-warnin-in-insert-data-to-db/ Share on other sites More sharing options...
fooDigi Posted February 23, 2008 Share Posted February 23, 2008 i believe you must specify which fields you wish to insert that data... insert into tblRegCo (field1, field2, etc...) values (data1, data2, etc.... Link to comment https://forums.phpfreaks.com/topic/92556-warnin-in-insert-data-to-db/#findComment-474282 Share on other sites More sharing options...
msafvati Posted February 23, 2008 Author Share Posted February 23, 2008 thank u as for your tells please show me one example from my script! Link to comment https://forums.phpfreaks.com/topic/92556-warnin-in-insert-data-to-db/#findComment-474285 Share on other sites More sharing options...
fooDigi Posted February 23, 2008 Share Posted February 23, 2008 well, what columns do you want to insert the data? do you want each of the 'txt*' values inserted into a different record? Link to comment https://forums.phpfreaks.com/topic/92556-warnin-in-insert-data-to-db/#findComment-474287 Share on other sites More sharing options...
msafvati Posted February 23, 2008 Author Share Posted February 23, 2008 thank u number of Columns that i want to insert are : 13 Link to comment https://forums.phpfreaks.com/topic/92556-warnin-in-insert-data-to-db/#findComment-474288 Share on other sites More sharing options...
fooDigi Posted February 23, 2008 Share Posted February 23, 2008 to modify your code... change each of column1, column2, etc... to the name of the columns you want to insert into <?php if (!strlen(trim($_GET['txt12']))) { echo "áØÝÇ äÇã ˜ÇÑÈÑí ÎæÏ ÑÇ æÇÑÏ äãÇííÏ"; die(); } $connectionstring = odbc_connect("User", "", ""); $query ="insert into tblRegCo (column1,column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,column13) values("; $query = $query."'".$_GET['txt1']."',"; $query = $query."'".$_GET['txt2']."',"; $query = $query."'".$_GET['txt3']."',"; $query = $query."'".$_GET['txt4']."',"; $query = $query."'".$_GET['txt5']."',"; $query = $query."'".$_GET['txt6']."',"; $query = $query."'".$_GET['txt7']."',"; $query = $query."'".$_GET['txt8']."',"; $query = $query."'".$_GET['txt9']."',"; $query = $query."'".$_GET['txt10']."',"; $query = $query."'".$_GET['txt11']."',"; $query = $query."'".$_GET['txt12']."',"; $query = $query."'".$_GET['txt13']."')"; $result = odbc_do($connectionstring,$query); echo "ÔãÇ ÈÇ ãæÝÞíÊ ÏÑ ÓíÓÊã ßÇÑíÇÈí ßÔæÑí ËÈÊ ÔÏíÏ " ; odbc_close($connectionstring); ?> Link to comment https://forums.phpfreaks.com/topic/92556-warnin-in-insert-data-to-db/#findComment-474289 Share on other sites More sharing options...
msafvati Posted February 23, 2008 Author Share Posted February 23, 2008 thnak you for help but i have this problem yet!!! Link to comment https://forums.phpfreaks.com/topic/92556-warnin-in-insert-data-to-db/#findComment-474295 Share on other sites More sharing options...
Sulman Posted February 23, 2008 Share Posted February 23, 2008 Your concatination is wrong: Try this: <?php if (!strlen(trim($_GET['txt12']))) { echo "áØÝÇ äÇã ˜ÇÑÈÑí ÎæÏ ÑÇ æÇÑÏ äãÇííÏ"; die(); } $connectionstring = odbc_connect("User", "", ""); $insert=""; $query=""; $insert ="insert into tblRegCo values("; $query = $query."'".$_GET['txt1']."',"; $query = $query."'".$_GET['txt2']."',"; $query = $query."'".$_GET['txt3']."',"; $query = $query."'".$_GET['txt4']."',"; $query = $query."'".$_GET['txt5']."',"; $query = $query."'".$_GET['txt6']."',"; $query = $query."'".$_GET['txt7']."',"; $query = $query."'".$_GET['txt8']."',"; $query = $query."'".$_GET['txt9']."',"; $query = $query."'".$_GET['txt10']."',"; $query = $query."'".$_GET['txt11']."',"; $query = $query."'".$_GET['txt12']."',"; $query = $query."'".$_GET['txt13']."')"; $result = odbc_do($connectionstring,$insert.$query); echo "ÔãÇ ÈÇ ãæÝÞíÊ ÏÑ ÓíÓÊã ßÇÑíÇÈí ßÔæÑí ËÈÊ ÔÏíÏ " ; odbc_close($connectionstring); ?> Your code kept adding "insert into tblRegCo values(" to the string leaving you with "insert into tblRegCo values('val, insert into tblRegCo values('val2'" etc... You can check this by echoing the query string to see what it contains. Link to comment https://forums.phpfreaks.com/topic/92556-warnin-in-insert-data-to-db/#findComment-474309 Share on other sites More sharing options...
fooDigi Posted February 23, 2008 Share Posted February 23, 2008 good point. always print out the sql statement and run it manually if you are stumped. *dang i missed that when i looked at the code! Link to comment https://forums.phpfreaks.com/topic/92556-warnin-in-insert-data-to-db/#findComment-474311 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.