Page 1 of 1

basic insert statement using odbc

Posted: Wed Apr 30, 2003 9:51 am
by ridwan
I am using the following code to insert info into a table:

Code: Select all

$strSQL="Insert into stationery (requested_by, item_needed, date_requested, type)"
            			. "('" . $txtRequestor . "','" . $txtItem . "','" . $txtDate . "','" . $txtType . "')";

            $execute= odbc_exec( $dbConnection, $strSQL);

            echo $strSQL;

	        odbc_close($dbConnection);
The echo is just to let me look at my sql statement.

I then get the error:
Warning: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '1'., SQL state 37000 in SQLExecDirect in C:\Program Files\Apache Group\Apache2\htdocs\php\bees\consumables\pagemaster.php on line 126
I have had a look for the error and it says that it is a syntax error but I dont see anything wrong with the syntax unless it is something I am not aware of

thanks all

Posted: Wed Apr 30, 2003 10:22 am
by gasoga
The only thing i can see is that you dont have VALUES in it!

Code: Select all

strSQL="Insert into stationery (requested_by, item_needed, date_requested, type)" 
                     . "('" . $txtRequestor . "','" . $txtItem . "','" . $txtDate . "','" . $txtType . "')"; 

            $execute= odbc_exec( $dbConnection, $strSQL); 

            echo $strSQL; 

           odbc_close($dbConnection);
The way i would write it is :

Code: Select all

$strSQL="INSERT INTO stationary(requested_by,item_needed,date_requested,type)VALUES('$txtRequestor','$txtItem','$txtDate','$txtType')";
$execute=odbc_exec($dbConnection,$strSQL);
Not sure if u can just echo the result like that think you might have to fetch it into an array !!
Hope this helps!!