Forum Moderators: coopster
<added>coopster on the same wavelength, same time ;)
[edited by: jatar_k at 2:11 am (utc) on Nov. 25, 2003]
$cur= odbc_exec( $cnx, "select ... from ... ");
I prefer to create the query statement, then plug it into the function. That way I can print my statement if I ever have issues like you are having. I recommend the practice:
$sql = "SELECT fields FROM table WHERE string='$string'";
// exit($sql); // uncomment this line to preview your statement.
$cur = odbc_exec($cnx, $sql);
>>same wavelength, same time...
jatar_k, How does the old Proverb go? Great Minds...
hehe
;)
<?php
$cnx= odbc_connect("test", " "," ");
$sql= "Select LastName, FirstName From test";
$cur= odbc_exec($cnx, $sql);
while(odbc_fetch_row($cur))
{
$LastName = odbc_result($result, 1);
$FirstName = odbc_result($result, 2);
print("$LastName $FirstName\n");
}
odbc_close($cnx)
?>
$cnx = odbc_connect( 'test2' , '', '' );
if (!$cnx) {
Error_handler( "Error in odbc_connect" , $cnx );
}
$SQL_Exec_String = "Insert Into People (fristname, lastname, phone)
Values ('$name','$lname','$pnum')";
$cur= odbc_exec( $cnx, $SQL_Exec_String );
if (!$cur) {
Error_handler( "Error2 in odbc_exec( no cursor returned ) " , $cnx );
}
i keep getting an error "Error2 in odbc_exec( no cursor returned )"
ive tried everthing i know.
test created with two fields in it and enter some data into the table. The two fields will be character strings, LastName and FirstName, so you may want to name them accordingly for clarification.
<?php
$cnx = odbc_connect('test', 'user','password') or exit("Could not connect to ODBC database!");
$sql = "SELECT * FROM test"; // The asterisk (*) says to select ALL fields
$result = odbc_exec($cnx, $sql) or exit(odbc_errormsg());
while(odbc_fetch_row($result)) {
$LastName = odbc_result($result, 1);
$FirstName = odbc_result($result, 2);
print("$LastName $FirstName\n");
}
odbc_close($cnx)
?>
<?php
$cnx = odbc_connect('test', 'user','password') or exit("Could not connect to ODBC database!");
$sql = "INSERT INTO test (LastName, FirstName) VALUES ('TestLastName', 'TestFirstName')";
odbc_exec($cnx, $sql) or exit(odbc_errormsg());
$sql = "SELECT * FROM test"; // The asterisk (*) says to select ALL fields
$result = odbc_exec($cnx, $sql) or exit(odbc_errormsg());
while(odbc_fetch_row($result)) {
$LastName = odbc_result($result, 1);
$FirstName = odbc_result($result, 2);
print("$LastName $FirstName\n");
}
odbc_close($cnx)
?>
OK, we're getting there. Regarding the last code snippet we we are using here (msg# 18) we should be getting an error message when we execute the INSERT INTO statement with the odbc_exec() function, correct? What errormsg is given?
>>its driving me crazy
Yeah, but the feeling you get when you overcome your issues is awesome -- hang in there ;)
This commonly occurs when you have a field name that is a reserved word.
Certain words (like table, field, date, note, select, password, level etc) are reserved by either ADO, OLEDB or by Access for use as commands or system objects.
You can get a list of reserved words in Access from the online help.
You should never use these words as names for tables or fields nor should you have spaces in your tablenames. It is recommended that you rename your offending tables/fields and adjust your SQL statement accordingly.
Hmmm. We aren't using any reserved words here...test, LastName, FirstName are not on the Access reserved word list...and we have single quotation marks around our values list. Well, we could try adding brackets around our fieldnames and/or we could also try changing the ODBC cursor type:
$cnx = odbc_connect('test', 'user','password', SQL_CUR_USE_ODBC) or exit("Could not connect to ODBC database!");
$sql = "INSERT INTO test ([LastName], [FirstName]) VALUES ('TestLastName', 'TestFirstName')";
There are several things that may cause this ODBC error. Possible reasons:
Q174640 - PRB: ASP: "The query is Not Updateable..." Error when Updating
Link: h**p://support.microsoft.com/default.aspx?scid=kb;EN-US;q175168
$sql = "DELETE FROM test WHERE LastName = 'TestLastName' AND FirstName = 'TestFirstName'";
The reason I ask for you to explain how you fixed the problem is so that future readers of this thread in this forum will be able to overcome the same obstacles you did. Thanks flying_monkey :)