Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Update and Insert Queries in PHP

Status
Not open for further replies.
Jul 14, 2003
116
CA
Hello,

I am trying to connect to an access db using PHP on and IIS server. I was able to write a SELECT query that worked but I can't quite figure out INSERT and UPDATE queries. Any ideas? See code below:

<?php
$db = 'database/nsbexl-nyc_db.mdb';
$conn = new COM('ADODB.Connection');
$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");

$sql = 'SELECT ID, referredBy
FROM membership_05_06
ORDER BY ID';
$rs = $conn->Execute($sql);

while (!$rs->EOF):
echo $rs->Fields['ID']->Value;
echo '<br>';
echo $rs->Fields['referredBy']->Value;
echo '<br>';

$rs->MoveNext();
endwhile;

$name = 'Alexander Keel';

$sql1 = 'INSERT INTO membership_05_06 (referredBy, gender)
VALUES (\'Alexander Keel\', \'Male\')';

$sql2 = "UPDATE membership_05_06
SET referredBy = 'Alexander Keel'
WHERE ID = 1";

echo $sql2;
echo '<br>' + $sql1;
$rs = $conn->Execute($sql2);

$rs->Close();
$conn->Close();

?>
 
By the way the error I am getting is:

Fatal error: Uncaught exception 'com_exception' with message 'Source: Microsoft JET Database Engine
Description: Operation must use an updateable query...
 
Still not really sure how to fix this. I checked the links above which all mention fixing the permissions but they don't really give clear cut directions. Any other thoughts?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top