php脚本插入数据库,不接收数据

php脚本插入数据库,不接收数据,php,mysql,Php,Mysql,我安装了phpmyadmin、mysql并在mac上激活了apache web服务器,可以作为本地主机很好地查看我的网页。我在这里遇到的困难是,每当我从我的联系人表单中输入详细信息时,它都不会在数据库中更新 联络表格: <Form Name="EnquiryForm" Method = "Post" Action = "contactprocess.php"> For further information please fill in the form below: &

我安装了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();
?>
您的查询应该是

$strengquiryadd=“在查询(id、姓名、电子邮件、号码、描述)值中插入
(“,$Name”,“$Emailaddress”,“$Contactnumber”,“$Description”);”

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

尝试使用

echo "<pre>";
print_r($_POST); // check what data returns
然后告诉我们发生了什么

此外,您还应该学习如何在php中设置错误报告并使用xdebug,它将在这一过程中为您提供很多帮助

手册中的示例

error_reporting(-1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
当您处于开发模式时,它会有所帮助


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

不,似乎没有任何错误。我两天前才在我的mac上安装了它,这样我就可以在家里工作了。在我的大学里,他们有完全相同的设置,当我使用上述脚本输入信息时,数据库会接收数据。您的查询很容易受到攻击,任何字段中的一个引号都会很容易打破这两个问题——您是否正确设置了表以自动递增id?您是否查看了apache日志文件中的错误消息?错误消息通常会以无效HTML的形式发送给您的网页——您可以尝试使用浏览器中的“工具->页面源”选项查看是否有任何隐藏消息,但这并不能回答问题。澄清的请求应该作为评论提出,但至少如果他在这里提出问题,我们可以帮助他了解如何调试代码,如何发现问题和其他问题。他从表格中获取数据,但他不知道表格是否提交。没有人反对。不过,这并不是OP问题的答案。不,那没有帮助,伙计。谢谢你的努力。表单确实会发送数据,但我想这与数据库的设置方式有关。我知道表单会发送数据:-),但在获取数据之前,您需要检查表单是否已提交。。你没有得到数据。。有一天你不知道为什么。与database.php相同,如果选择了database,则需要检查是否建立了连接,以此类推。另一个好的实践是使用php的pdo扩展。更好的安全性,将帮助您编写更好的代码,更简单。
<?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');