嗨,我设置了两段代码
<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>
和这个名为Index2.php的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);
?>
我曾尝试在一个单独的文件中确保连接并将信息传递给数据库,但是当我运行表单时,它没有将数据传递给MS Access并在空白页面上显示了PHP代码,缺少从PHP转义的某种方式?
答案 0 :(得分:1)
我已经尝试过这个方法了。
<?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";
}
}
?>