I can't figure this out - maybe I just need a fresh look at it. ALL of my SQL statements work except this one - the database is correct, the fields are correct but I get

"Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement., SQL state 37000 in SQLExecDirect in \admin\newsupdate.php on line 73"

Like I said, all my other commands execute fine and I just copied and pasted my code and it will not process this one. Any ideas? Here's my code:

if ($action == 'add')
{
echo "
<a href='newsupdate.php'>Go Back...</a><br>
<form method='post' action='newsupdate.php?action=addprocess'>
Enter date associated with news item<br>
<b>Format 11/30/2001</b>:<br>
<input type='text' name='dte' size='8' maxlength='10'><br><br>

  Enter news description:<br>
  <textarea name='desc' rows='5' cols='30'></textarea><br>
  <input type='submit' value='Submit'>&nbsp;&nbsp;&nbsp;<input type='reset' Value='Reset'>
  ";
}

if ($action == 'addprocess')
{
  $conn = odbc_connect( 'cvcdata', 'root', '' );
  $query = "INSERT INTO news (dte, desc) VALUES ('$dte', '$desc')";
  odbc_exec($conn, $query);
  odbc_Close($conn);
  print "News item added. Click <a href='newsupdate.php'>here</a> to return.";
}

Thanks!

    I assume that you are using the "short date" field type for your access database? Are you validatin to make sure that the correct date is entered?

      change:

      $query = "INSERT INTO news (dte, desc) VALUES ('$dte', '$desc')";

      To:

      $query = "INSERT INTO news (dte, desc) VALUES ('" . $dte . "', '" . $desc . "')";

      -- Rich

        actually, it is entered just as "text". I thought that might be it, so I tried the same thing without the date at all and just with the desc and it does the same thing.

          Nope, same error.

          Thanks anyway -

            Try:

            $query = "INSERT INTO news (dte, desc) VALUES ('" . addslashes($dte) . "', '" . $desc . "')";

            In case the slashes in the date are messing up the query...

            -- Rich

              Bummer again, I tried entering the data in just straight text with still the same error.

                ...well i'm stumped. Your SQL looks fine. The only other thing I would do is put the = <i>odbc_connect()</i> into an <i>if()</i> statement to make sure you are really connected to the database before execute the SQL.

                -- Rich

                  desc must be a keyword in Access. Once I changed it to something else, it worked fine.

                  Thanks again for your help,

                  Seth

                    Write a Reply...