php - 向表中插入表单数据

标签 php postgresql

我的表单通过电子邮件将数据发送给客户好吧,我还需要它来将该数据保存到名为 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 
} 
?>

最佳答案

$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');

关于php - 向表中插入表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31288968/

相关文章:

php - 当 PDO 中的其他一切正常时,无法执行 PDO 语句(更新 MySQL 表)

php - yii 组件 : events and behaviors?

javascript - 如何使用 Jest/Supertest/Knex/Postgres 处理外键约束

sql - 如何创建将一个表中的序列号添加到另一个表中的 INSERT 查询

ruby-on-rails - 如何在 Rails 中定义 postgres 函数以及它们的范围和生命周期是什么?

sql - 编写 SQL 查询时遇到问题 多对多关系

php - ajax,以 json 形式检索多维 php 数组

php - 如何按特定表顺序构造输出数据

php - 如何在选择 onChange 事件时重定向到其他方式?

sql - 如何在 PostgreSQL 中使用带有 RANDOM() 函数的 SELECT DISTINCT?