Jump to content

warnin in Insert Data to DB


msafvati

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.