1

I want to connect PHP to access DB and insert values from my forms, but it is not working. The bottom code shows HTML form, I want to add Combobox to access DB as well.

ERROR MESSAGE :

Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement., SQL state 37000 in SQLExecDirect in C:\xampp\htdocs\insert\save.php on line 14 Failed

The form inserted before now it is not working

<?php 

if(isset($_POST['submit'])) {
    $date = $_POST['date'];
    $address = $_POST['address'];
    $township = $_POST['township'];
    $description = $_POST['description'];
    echo $date." ".$address." ".$township." ".$description; 
    echo"<br>";
    echo"<br>";

    $con = odbc_connect("studentinfo","","");
    $insert_data = "INSERT INTO Tie_In_Entry 
                                (Date, Address, Township, Description) 
                    VALUES ('$date','$address','$township','$description')";
    if (odbc_exec($con, $insert_data)) {
        echo "Database Connected & Inserted";
        header("refresh:1;url=index.php");
    }else{
        echo "Failed";
    }
}
?>

<input placeholder= "date" type="text" name="date" >
<br>
<input placeholder= "address" type="text" name="address" >
<br>
<input placeholder= "township" type="text" name="township" >
<br>
<input placeholder= "wo" type="text" name="wo" >
<br>
<input placeholder= "description" type="text" name="description" >
<br>
<input type="submit" name="submit" value = "Submit">
Long Luong
  • 764
  • 2
  • 14
  • 28
  • Please check your query and also you are creating SQL injection. See [here](https://www.w3schools.com/sql/sql_injection.asp) or [What is SQL injection](https://portswigger.net/web-security/sql-injection). Take a look at [how to prevent SQL injection](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Long Luong Dec 23 '20 at 22:53
  • you have no `
    ` tags in what you posted. Is this just a snippet? It will need to be inside a `
    ` for it to take effect. Also, why the `ms-access-2010` tag?
    – Joshua Dec 24 '20 at 04:59

0 Answers0