php脚本插入到数据库不接受数据


php script INSERT into database not taking in data

我安装了phpmyadmin, mysql,并在我的MAC上激活了apache web服务器,可以像本地主机一样查看我的网页。我在这里挣扎的是,每当我从我的联系表单中输入详细信息时,它不会在数据库中更新。

接触形式:

<Form Name="EnquiryForm" Method = "Post" Action = "contactprocess.php">
For further information please fill in the form below:
      <p>
        Name: <Input Type = "Text" Size="40" Name="Name">
      <p>
        Email Address: <Input Type = "Text" Size="40" Name="Emailaddress">
      <p>
        Contact Number: <Input Type = "Text" Size="40" Name="Contactnumber">
      <p>
        Description:<TextArea Rows="5" Cols="60" Name="Description">
                </TextArea>
    <p>
        <Input  Type  = "Submit" name  = "Submit" Value = "Submit">
        <Input  Type  = "Reset" name  = "Reset"Value = "Reset">
</Form>

php脚本进入数据库,联系process.php:

<?
session_start();
include('database.php');
//Define variables from form to put into table
$Name = $_POST['Name'];
$Emailaddress= $_POST['Emailaddress'];
$Contactnumber = $_POST['Contactnumber'];
$Description = $_POST['Description'];
$strEnquiryadd = "INSERT INTO enquiries VALUES
('','$Name','$Emailaddress','$Contactnumber','$Description');";
mysql_query($strEnquiryadd);
mysql_close();
$_SESSION['login'] = "1";
$_SESSION['userid'] = $userid;
header ("Location: contact us.php");
session_destroy();
?>

你的查询应该是

$strEnquiryadd = "INSERT INTO enquiries (id,name,email,number,description) VALUES ('','$Name','$Emailaddress','$Contactnumber','$Description');";

显然将列名更改为表中使用的列名

尝试使用

echo "<pre>";
print_r($_POST); // check what data returns
然后

if(isset($_POST['Submit'] {
    // Run here your code
}

然后告诉我们发生了什么

你还应该学习如何在php中设置错误报告,并使用xdebug,它将在此过程中帮助你很多。

手册中的例子

<?php
// Turn off all error reporting
error_reporting(0);
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
// Report all PHP errors
error_reporting(-1);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
?>

我看到这样不确定是否可以也许有人会纠正我

error_reporting(-1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');

当你处于开发模式时,它会有帮助。

你的代码的另一个问题是你没有提供任何安全性。有了这些代码,你可以得到一个非常好的sql注入。