php mail()同时将数据保存到MYSQL

时间:2017-11-04 21:14:54

标签: php mysql email

嗨,请一点点我在这里找不到我的错误。 当用户点击发送时,我需要发送的邮件以及要存储在"用户"中的数据。表。现在邮件工作我收到邮件,但数据没有保存在数据库中?为什么?我知道我的代码需要大量工作,因为它没有得到优化。

如果我在mysql数据库中运行它,它可以正常工作:

INSERT INTO uporabniki(IME,PRIIMEK,TELEFON,IZOBRAZBA,EMAIL,OKP,OPS,ODS)价值观(' rr',' dd'' 123&#39 ;,'悲伤',' rr@ee.com',' 1'&#39 2'&#39 3' )

<?php
   include("config.php");
   session_start();


$update_ime=$_POST['ime'];
$update_priimek=$_POST['priimek'];
$update_email=$_POST['email'];
$update_telefon=$_POST['telefon'];
$update_izobrazba=$_POST['izobrazba'];
$update_kraj=$_POST['kraj'];

$update_okp=$_POST['prijava_okp'];
$update_ops=$_POST['prijava_ops'];
$update_ods=$_POST['prijava_ods'];


$sql = "INSERT INTO uporabniki(IME,PRIIMEK,TELEFON,IZOBRAZBA,EMAIL,OKP,OPS,ODS)
VALUES ('$update_ime','$update_priimek','$update_telefon','$update_izobrazba','$update_email','$update_okp','$update_ops','$update_ods')";


$result1 = mysqli_query($db,"SELECT DATUM, HOUR FROM razpisani_tecaji WHERE ID_TECAJA = '$update_okp'");
while($row = mysqli_fetch_array($result1)){
$date1 = $row['DATUM']; 
    $hour1 = $row['HOUR']; 
}

$result2 = mysqli_query($db,"SELECT DATUM, HOUR FROM razpisani_tecaji WHERE ID_TECAJA = '$update_ops'");
while($row = mysqli_fetch_array($result2)){
$date2 = $row['DATUM']; 
    $hour2 = $row['HOUR']; 
}

$result3 = mysqli_query($db,"SELECT DATUM, HOUR FROM razpisani_tecaji WHERE ID_TECAJA = '$update_ods'");
while($row = mysqli_fetch_array($result3)){
$date3 = $row['DATUM']; 
    $hour3 = $row['HOUR']; 
}


$to      = 'info@viverius-education.com,rok.ivartnik@viverius.com';
$subject = 'Prijava na tečaj';
$headers = "From: {$update_email} <{$update_email}>\r\n";
$message  = "--------------------------------------------------- \r\n";
$message  .= "Prijavljam se na tečaje: \r\n";
$message  .= "--------------------------------------------------- \r\n";
$message  .= "Online klinični primeri: " . $date1 ." " .$hour1. "\r\n";
$message  .= "Online priprave na strokovni izpit: " . $date2 ." " .$hour2. "\r\n";
$message  .= "Online delavnice za študente medicine: " . $date3 ." " .$hour3. "\r\n";
$message  .= "--------------------------------------------------- \r\n";
$message  .= "Podatki o udeležencu: \r\n";
$message  .= "Ime: " . $update_ime . "\r\n";
$message  .= "Priimek: " . $update_priimek . "\r\n";
$message  .= "Email: " . $update_email . "\r\n";
$message  .= "Telefon: " . $update_telefon . "\r\n";
$message  .= "Status/izobrazba: " . $update_izobrazba . "\r\n";
$message  .= "Ime ustanove/kraja: " . $update_kraj . "\r\n";
$message  .= "--------------------------------------------------- \r\n";


if(mail($to, $subject, $message, $headers)){
 header('Location: email_uspesno_poslan.html'); exit;
}else{
 header('Location: email_neuspesno_poslan.html'); exit;
}

?>

1 个答案:

答案 0 :(得分:1)

您从未执行过sql查询。使用方法来执行它,例如

$db->query($sql) 

或使用mysqli

mysqli_query($db, $sql)