Hi,

I'm having trouble updating an Access databasewith PHP. I can read from a table in the database no problem, but i can't insert data. Also i get no error messages, the html form executes, but when i open the table in access there is no data added. My code is attached below, any help is appreciated,

Joe

<html>
<body>
<?php

ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_NOTICE);

if(isset($_POST['submit']))
{ //handle the form



  $conn=odbc_connect('dentalrecords','','');
   if (!$conn)
   {
    exit("Connection Failed: " . $conn);
   }

  $sql="INSERT INTO 'Table1'('field1')
                 VALUES('{$_POST['field1']}')";

  $result=odbc_exec($conn, $sql)or die (odbc_errormsg());

  if($result){
        echo "Query Executed";
  }else{
       	echo "Query failed " .odbc_error();
  }

  odbc_close($conn);

}
//endof form handling


?>
<form action="EnterDetails1.php" method="POST">

<p>Enter Trace Number: <input type="text" id="field1" size="40" /></p>
<input type="submit" id="submit" value="Enter Data" />

</form>

</body>
</html>

    You connection and code is correct. Try a different approach.
    Get rid of the extras

    $field1 = $_POST["field1"];
    $sql="INSERT INTO Table1 (field1) VALUES ('$field1')";

      Hi Frederick,

      I've tried your suggestion however it's made no change. When i open Access and open the db table there are no entries made

        yes it will be in an intranet environment, but i've done all that already. I don't understand why this is not working. Can you send me some code for an php form updating an Access table that you know works?

        thanks

          Check the attachment and see if it is wnat you use. The attachment has 3 items in it that hits all areas of database access.

            Write a Reply...