Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
General
cancel
Showing results for 
Search instead for 
Did you mean: 

Error on Database Acess using PHP

SOLVED
Go to solution
Ricardo Bassoi
Regular Advisor

Error on Database Acess using PHP

 
If you never try, never will work
6 REPLIES
benoit Bruckert
Honored Contributor

Re: Error on Database Acess using PHP

Hi bassoi,
I'm not an expert in access, but you have a php syntax error when you define this string :
$SQL_Exec_String = "Insert Into real (Cliente, Projeto) values ('$cliente', '$projeto')";

the $ are included in your string which means that if cliente=5 (if it's numeric), you will include $cliente (an alpha string) and not 5.
in order to include the values you have to quit the string with the " and concat your values with it.
Example :
$five=5;
$fivestringgood="this is ".$five;
$fivestringbad="this is $five";

an echo of fivestringbad :
this is $fivea
an echo of fivestringgood :
this is 5

nota : don't forget the dot . to concat strings.
For your string the correct syntax should be :
$SQL_Exec_String = "Insert Into real (Cliente, Projeto) values ('".$cliente."', '".$projeto."')";
Une application mal pansée aboutit à une usine à gaze (GHG)
Ricardo Bassoi
Regular Advisor

Re: Error on Database Acess using PHP

Hi,

I still have the error :

Warning: SQL error: [Microsoft][Driver ODBC para Microsoft Access] Erro de sintaxe na instru????o INSERT INTO., SQL state 37000 in SQLExecDirect in C:\Arquivos de programas\Apache Group\Apache2\htdocs\insert.php3 on line 41
Error in odbc_exec( no cursor returned )


Regards,

Bassoi
If you never try, never will work
benoit Bruckert
Honored Contributor

Re: Error on Database Acess using PHP

HI,
if i interpret properly, i think the trouble is then with the cursor exec function :
lines:

$SQL_Exec_String = "Insert Into real (Cliente, Projeto) Values ('$cliente', '$projeto')";

$cur= odbc_exec( $cnx, $SQL_Exec_String );
if (!$cur) {
Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );
}

you are in the case Error_handler !
then odbc_exec generated an error.
To check the sql syntx, the easiest way is to echo your string before execute :
I.E.
echo $SQL_Exec_String;
just before odbc_exec.
nota, the proper syntax is '".$cliente."','".$projeto."'
Then you can see exactly what is sent to the database. May be it's just an numeric trouble :
Does you cliente column is numeric in your database, or projeto column.
If this is the case, remove the singles quotes (') of the appropriate column in the insert statement.
You can also cut and paste the output of the echo to check directly with access the syntax of your insert statement. By this way, you may have more details about the error...(probably a syntax error).

hth
Benoit
Une application mal pansée aboutit à une usine à gaze (GHG)
Ricardo Bassoi
Regular Advisor

Re: Error on Database Acess using PHP


Hi,

The result now is:

Insert Into real (Cliente, Projeto) values ('Test1', 'Test2')
Warning: SQL error: [Microsoft][Driver ODBC para Microsoft Access] Erro de sintaxe na instru????o INSERT INTO., SQL state 37000 in SQLExecDirect in C:\Arquivos de programas\Apache Group\Apache2\htdocs\insert.php3 on line 42
Error in odbc_exec( no cursor returned )
--------------------------------------------

And the code is:

function Enter_New_Entry($cliente,$projeto) {

/*
First, we create a connection to our ODBC source. This is done by creating
a connection. Once this is done, we are returned an ODBC connection number.
We use this number to use the ODBC functions within PHP.
*/

$cnx = odbc_connect( 'teste' , '', '' );
if (!$cnx) {
Error_handler( "Error in odbc_connect" , $cnx );
}
$SQL_Exec_String = "Insert Into real (Cliente, Projeto) values ('".$cliente."', '".$projeto."')";

echo $SQL_Exec_String;
$cur= odbc_exec( $cnx, $SQL_Exec_String );
if (!$cur) {
Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );
}


odbc_close( $cnx);
}

$strNewEntries = "Atualiza????o do Workload Concluida";

HTML_Head();
$cliente="Test1";
$projeto="Test2";
Enter_New_Entry($cliente,$projeto);


Regards,

Bassoi

If you never try, never will work
benoit Bruckert
Honored Contributor
Solution

Re: Error on Database Acess using PHP

hi,
from google, ODBC 37000 is syntax error or access violation error. I think it's the first .
try to send
Insert Into real (Cliente, Projeto) values ('Test1', 'Test2')
directly with access.. and check the result.
OR try with this :
Insert Into real values ('Test1', 'Test2')
if you don't have more columns in your real table.
May be "real" is a reserved word! try another name...
I'm quite sure that the error is on the odbc/msaccess side.

hope that help...
Benoit
Une application mal pansée aboutit à une usine à gaze (GHG)
Ricardo Bassoi
Regular Advisor

Re: Error on Database Acess using PHP

Hi,

The problem was in the name "real",probably is a reserved word. I rename it and work??s.

Thanks,

Bassoi
If you never try, never will work