我安装了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();
?>
答案 0 :(得分:1)
您的查询应该是
$strEnquiryadd = "INSERT INTO enquiries (id,name,email,number,description) VALUES
('','$Name','$Emailaddress','$Contactnumber','$Description');";
显然将列名更改为表中使用的列名。
答案 1 :(得分:0)
尝试使用
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注入。