我正在尝试使用以下MySQL语句将表单中的insert
数据发布到我的数据库中,但它产生了我的错误'Oooops! *** **** ***'
我知道有一个连接,因为在我插入任何内容之前,我会测试用户的电子邮件地址以查看它是否已经存在,如果是,它会将用户重定向到登录状态。这样做是有效的,如果数据库中不存在电子邮件,那么它应该是插入表单数据,但事实并非如此。 *有人可以告诉我我哪里错了吗?我已经确定我正在拼写表名正确和所有内容,并且100%确定我已正确发布所有表单数据。
<?php
session_start();
include("config.php");
include("verify.php");
//retrieve our data from POST
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$email2 = $_POST['email2'];
$contactnum = $_POST['contactnum'];
$mobnum = $_POST['mobnum'];
$postcode = $_POST['postcode'];
$addres1 = $_POST['address1'];
$addres2 = $_POST['address2'];
$town = $_POST['town'];
$compname = $_POST['compname'];
$compreg = $_POST['compreg'];
$verify = $_POST['verify'];
$verification = $_POST['verification'];
$firstname = stripslashes($firstname);
$firstname = mysql_real_escape_string($firstname);
$lastname = stripslashes($lastname);
$lastname = mysql_real_escape_string($lastname);
$email = stripslashes($email);
$email = mysql_real_escape_string($email);
$email2 = stripslashes($email2);
$email2 = mysql_real_escape_string($email2);
$contactnum = stripslashes($contactnum);
$contactnum = mysql_real_escape_string($contactnum);
$mobnum = stripslashes($mobnum);
$mobnum = mysql_real_escape_string($mobnum);
$postcode = stripslashes($postcode);
$postcode = mysql_real_escape_string($postcode);
$addres1 = stripslashes($addres1);
$addres1 = mysql_real_escape_string($addres1);
$addres2 = stripslashes($addres2);
$addres2 = mysql_real_escape_string($addres2);
$town = stripslashes($town);
$town = mysql_real_escape_string($town);
$compname = stripslashes($compname);
$compname = mysql_real_escape_string($compname);
$compreg = stripslashes($compreg);
$compreg = mysql_real_escape_string($compreg);
$verify = stripslashes($verify);
$verify = mysql_real_escape_string($verify);
$verification = stripslashes($verification);
$verification = mysql_real_escape_string($verification);
$query = sprintf("SELECT * FROM supplier_registration WHERE supplier_email='%s'", mysql_real_escape_string($email2));
$result = mysql_query($query);
if(mysql_num_rows($result) > 0) {
$_SESSION['message2'] = '<div id="message_box3"><div class="boxclose" id="boxclose" onclick="this.parentNode.parentNode.removeChild(this.parentNode);"></div><h23>Found You!</h23><p>It appears that a user with that email address is already registered. Please Login below or click on our support section.</p> </div>';
header('Location: ../login.php');
} else {
$sql = "INSERT INTO supplier_registration (id, first_name, last_name, supplier_email, contact_number, mobile_number, postcode, address1, address2, town, company_name, company_reg, date) VALUES (NULL, '$firstname','$lastname','$email2', '$contactnum', '$mobnum', '$postcode', NULL, NULL, NULL, '$compname', '$compreg', now())";
$result2 = mysql_query($sql);
if(mysql_num_rows($result2) > 0) {
$_SESSION['message2'] = '<div id="message_box3"><div class="boxclose" id="boxclose" onclick="this.parentNode.parentNode.removeChild(this.parentNode);"></div><h23>Thanks for Registering!</h23><p>You have successfully registered. We have sent you a verification email.</p> </div>';
header('Location: ../index.php');
}else{
$_SESSION['message2'] = '<div id="message_box3"><div class="boxclose" id="boxclose" onclick="this.parentNode.parentNode.removeChild(this.parentNode);"></div><h23>Oooops!</h23><p>It appears there was an error whilst attempting to register your details. Please try again later.</p> </div>';
header('Location: ' . $_SERVER['HTTP_REFERER']);
} }
?>
答案 0 :(得分:0)
错误可能与表中字段的数据类型有关。
在您的代码中,没有字符串转换为数字。
如果您将表定义和确切的SQL错误添加到您的问题中,可以提供更多帮助。
答案 1 :(得分:0)
试试这个..
$sql = "INSERT INTO supplier_registration (id, first_name, last_name, supplier_email, contact_number, mobile_number, postcode, address1, address2, town, company_name, company_reg, date) VALUES ('', '$firstname','$lastname','$email2', '$contactnum', '$mobnum', '$postcode', '', '', '', '$compname', '$compreg', now())";
$result2 = mysql_query($sql);
答案 2 :(得分:0)
这是因为您的查询中的date
是 Reserved Keyword 。所以你必须像[]
[date]