我的表单将数据通过电子邮件发送给客户,我还需要它将数据保存到名为card的表中,而不是这样。请让我知道我哪里出错了。我几乎肯定这与我连接数据库时有关。
<?php
if(isset($_POST['email'])) {
$email_to = ($_POST['email']);
$email_subject = "Customer Registration";
function died($error) {
// sese
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// siati data
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['pay_address1']) ||
!isset($_POST['pay_address2']) ||
!isset($_POST['pay_address3']) ||
!isset($_POST['pay_address4']) ||
!isset($_POST['pay_contact_no']) ||
!isset($_POST['email']) ||
!isset($_POST['password']) ||
!isset($_POST['security'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // manaomia
$last_name = $_POST['last_name']; // manaomia
$address1 = $_POST['pay_address1']; // manaomia
$address2 = $_POST['pay_address2']; // manaomia
$address3 = $_POST['pay_address3']; // manaomia
$address4 = $_POST['pay_address4']; // manaomia
$reference = $_POST['email']; // manaomia
$customer_pass = $_POST['password']; // manaomia
$contact_no = $_POST['pay_contact_no']; // pule oe
$security = $_POST['security']; // manaomia
$dbconn = pg_connect("host=127.0.0.1 dbname=ina user=suser password=ABCDEFG") or die('Could not connect: ' . pg_last_error());
$query = "INSERT INTO card (reference, first_name, last_name, address1, address2, address3, address4, contact_no, customer_pass) VALUES ($reference, $first_name, $last_name, $address1, $address2, $address3, $address4, $contact_no, $customer_pass)";
$result = pg_query($query);
if (!$result)
{
echo "Customer update failed!!";
} else
{
echo "Update was successfull; ";
}
pg_close();
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$reference)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid. <br />';
}
if(strlen($security) != 5) {
$error_message .= 'The Translation you entered do not appear to be valid. <br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Your login details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Login ID: ".clean_string($reference)."\n";
$email_message .= "Password: ".clean_string($password)."\n";
// email headers
$headers = 'From: ' . $from . "\r\n";
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
Thank you for registering. An email containing your login id and a password was sent to the provided email address. Please check your mail and then log in to continue.
NEXT Button
<?php
}
?>
答案 0 :(得分:0)
$dbconn = pg_connect("host=127.0.0.1 dbname=ina user=suser password=ABCDEFG") or die('Could not connect: ' . pg_last_error());
$query = "INSERT INTO card ('reference'=>$reference, 'first_name'=>$first_name, 'last_name'=>$last_name, 'address1'=>$address1, 'address2'=>$address2, 'address3'=>$address3, 'address4'=>$address4, 'contact_no'=>$contact_no, 'customer_pass'=>$customer_pass,'security'=>$security)";
//or use where condition
//INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
//VALUES ('Cardinal','Tom B. Erichsen','Skagen 21','Stavanger','4006','Norway');