1

Hi I have two pieces of code set up

<form action="Index2.php" method="POST">
    <p>Name:</p>
    <input type="text" name="name">

    <p>Last Name:</p>
    <input type="text" name="lname">

    <input type="submit" value="Submit">
</form>

and this PHP file named Index2.php

<?php

$connection = odbc_connect("Dashboard","","") or die ("Unable to Connect to the DB");

$name=$_POST['name'];
$last_name=$_POST['lname'];

$sql = "
    INSERT INTO tableone (Name, Last_Name)
    VALUES ('$name', '$last_name')
";

odbc_exec($connection, $sql);
?>

That I have tried in a separate file to make sure connects and pass the info to the database but when I run the form it does not pass the data to MS Access and shows me the PHP code on a blank page, am I missing some sort of escaping from PHP?

Erik A
  • 31,639
  • 12
  • 42
  • 67
  • can you try this instead: ` $sql = " INSERT INTO tableone (Name, Last_Name) VALUES ('" . $name . "', '" . $last_name . "') ";` – I am Cavic Sep 20 '18 at 05:17
  • Does any Php code get interpreted in your server environment? Something like ` – Progrock Sep 20 '18 at 05:22
  • 1
    Check out [this post](https://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-shows-on-the-page) which talks about configuration issues. Sounds like your php code is not being processed. – mseifert Sep 20 '18 at 05:25
  • I thought this most likely will be the problem, I will check it and try to solve the excecution of the php code on my environment – Edward Gavilán Sep 21 '18 at 19:04
  • this is displayed, so php gets excecuted – Edward Gavilán Sep 21 '18 at 19:10
  • @IamCavic, I tried this sentece, althought it does not give me any error it does not get written into the Access DB. They query is right, I tried alone, I think the problem is with php and html, something do not clicked right there – Edward Gavilán Sep 21 '18 at 19:25

1 Answers1

1

I have tried this and its working.

<?php
if(isset($_POST['submit]))
{
$name=$_POST['name'];
$last_name=$_POST['lname'];
$con=odbc_connect("abc","","");
$sql="INSERT INTO tableone(name,lastname) VALUES('$name','$last_name')";
if(odbc_exe($con,$sql))
{
    echo "<br>Data Added<br>Please wait ,Page is redirecting";  
    header("refresh:1;url=index.php");
}
else
{
    echo "Error";
}
}   
?>
piet.t
  • 11,718
  • 21
  • 43
  • 52
Prathamesh Doke
  • 797
  • 2
  • 16
  • 38