2017-03-10 3 views
-1

사용자의 이메일을 요구 한 다음 이름, 성 및 핸드폰 번호를 보내는 양식을 테스트하고 있습니다. 이제 모든 것이 작동합니다. 입력 된 이메일에 따라 사용자를 선택합니다. 이메일을 보냅니다.테이블에서 데이터를 가져올 수 없습니다.

유일한 문제는 내가 보내는 데이터에 테이블의 데이터를 삽입하는 것입니다.

Eg.$mail->Body  = "Your company details are: " Name,Surname,Cellphone; 

내가 현재 직면 한 문제입니다. 내 전체 코드는 아래와 같습니다.

나는 PHP에서 아직 완전히 익숙하지 않기 때문에 일반적인/일반적인 오류 일 경우 사과드립니다.

<?php 

error_reporting(1); 
ini_set('error_reporting', E_ALL); 
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="****"; // Mysql password 
$db_name="Username"; // Database name 
$tbl_name="Name"; // Table name 

// Connect to server and select databse. 
$conn = mysqli_connect($host, $username, $password, $db_name); 

// Define $username and $password 
$username=$_POST['user_name']; 

$sql="SELECT * FROM $tbl_name WHERE Name='$username'"; 
$result=mysqli_query($conn, $sql); 

// Mysql_num_row is counting table row 
$count=mysql_num_rows($result); 
if ($count > 0) 
{ 

require 'PHPMailer-master/PHPMailerAutoload.php'; 

$mail = new PHPMailer; 

$mail->IsSMTP(); // telling the class to use SMTP 
$mail->Host  = "****"; // SMTP server      // enables SMTP debug information 
$mail->SMTPAutoTLS = false; 
$mail->SMTPSecure = false; 
$mail->SMTPAuth = true;     // enable SMTP authentication 
$mail->Host  = "****"; // sets the SMTP server 
$mail->Port  = 587;     // set the SMTP port for the GMAIL server 
$mail->Username = "****"; // SMTP account username 
$mail->Password = "****";  // SMTP account password 
$mail->From = "Test"; 
$mail->FromName = "Test"; 

$mail->AddAddress($username, ""); 

$mail->isHTML(true); 

$mail->Subject = 'Out Of Office Password'; 
$mail->Body  = "Your Out Of Office password: "; 

if(!$mail->Send()) 
{ 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
    exit(); 
} 
else 
{ 
    echo 'Email Sent Successfully!'; 
} 

} 

>

형태 :

<center> 
<html> 
<head> 
<title>User Information</title> 
</head> 
<body> 
<form action="check-user.php" method="POST"> 
    <h3>User Information</h3> 

    Email: <input type="text" name="user_name"><br> 

    <input type="submit" name="submit" value="Send Info"> 
</form> 
</body> 
</html> 
</center> 
+1

'mysql' =='내가 – C2486

+0

@Niklesh을 mysqli'하지만 지금은 내 이메일 – RedZ

답변

1

먼저

$conn = mysqli_connect($host, $username, $password, $db_name) 
// if u get connection valid message delete this if statement this is just for testing your connection 
if ($conn) { 
    echo 'connection valid'; 
} else { 
    echo 'connection invalid ' . mysqli_error($conn); 
} 

연결이 유효하게 그리고 u는이

echo "Connected to MySQL<br />"; 
mysqli_select_db("$db_name") or die(mysqli_error()); 
echo "Connected to Database<br />"; 
필요하지 않습니다

변경이 줄을

$result=mysqli_query($conn, $sql); 

그리고이 하나

if ($count > 0) { 

그리고 U 신규 PHP에, 난 유, 데이터베이스에 연결 error_reporting은 확인/갱신/삽입을 확보하는 방법에 대해 자세히 알아이어야 필요가 있다고 생각하기 때문에/데이터베이스에 데이터를 삭제하십시오.

내 생각으로는 사용을 배우기 시작하면 PDO with prepared statements 안전합니다. 이 mysqli을 벗어나지 않으면 보안상의 문제가 발생할 수 있습니다.

편집 :!

<?php 
ob_start(); 
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="****"; // Mysql password 
$db_name="Username"; // Database name 
$tbl_name="Name"; // Table name 

// Connect to server and select databse. 
$conn = mysqli_connect($host, $username, $password, $db_name) or die(mysqli_error($conn)); 

if (isset($_POST['submit'])) 
{ 
    // Define $username 
    $username = $_POST['user_name']; 

    $sql = "SELECT * FROM $tbl_name WHERE Name='$username'"; 
    $result = mysqli_query($conn, $sql); 

    // Mysql_num_row is counting table row 
    $count = mysqli_num_rows($result); 

    if ($count > 0) 
    { 

    // get data from user 
    $data = mysqli_fetch_array($result, MYSQLI_ASSOC); 

    require 'PHPMailer-master/PHPMailerAutoload.php'; 

    $mail = new PHPMailer; 

    $mail->IsSMTP(); // telling the class to use SMTP 
    $mail->Host = "****"; // SMTP server // enables SMTP debug information 
    $mail->SMTPAutoTLS = false; 
    $mail->SMTPSecure = false; 
    $mail->SMTPAuth = true; // enable SMTP authentication 
    $mail->Host = "****"; // sets the SMTP server 
    $mail->Port = 587; // set the SMTP port for the GMAIL server 
    $mail->Username = "****"; // SMTP account username 
    $mail->Password = "****"; // SMTP account password 
    $mail->From = "Test"; 
    $mail->FromName = "Test"; 

    $mail->AddAddress($username, ""); 

    $mail->isHTML(true); 

    $mail->Subject = 'Your Company Details'; 
    $mail->Body = "Your company details are: Name: = " . $data['Name'] . ", Surname: " . $data['Surname'] . ", Cellphone: " . $data['Cellphone']; 

    if(!$mail->Send()) 
    { 
     echo 'Message could not be sent.'; 
     echo 'Mailer Error: ' . $mail->ErrorInfo; 
     exit(); 
    } 
    else 
    { 
     echo 'Email Sent Successfully!'; 
    } 

} 

ob_end_flush(); 
?> 
+0

이 확인이 다시 유효 온다 생각 그들 모두를 고정 – RedZ

+0

을 보내기에 실패 말씀 오류가 발생했습니다 –

+0

어떤 오류가 표시되지 않습니다 – RedZ

관련 문제