2017-04-25 23 views
0

4つのフォーム入力で完全なウェブサイトを作成しました。入力はテキスト入力であり、MySQLデータベースに接続されています。今私はそれらのテキスト入力の1つをテキストボックスに変更したいと思います。それを行うと、特定の 'メッセージ'フィールドのためにデータベースにデータをもう送信しません。データベースに影響を与えずにテキストエリアに入力フォームを変更

//php code to insert to db 
 
<?php 
 

 
$errors   = array(); \t // array to hold validation errors 
 
$data \t \t \t = array(); \t \t // array to pass back data 
 
$email = $_POST['email']; 
 
$phone = $_POST['phone_number']; 
 
$name = $_POST['name']; 
 
$message=$_POST['message']; 
 

 
// validate the variables ====================================================== 
 
\t // if any of these variables don't exist, add an error to $errors array 
 

 
\t if (empty($_POST['name'])) 
 
\t { 
 
\t \t $errors['name'] = 'Name is required.'; 
 
\t } 
 

 
\t if (empty($_POST['email'])) 
 
\t { 
 
\t \t $errors['email'] = 'Email is required.'; 
 
\t } else { 
 
\t \t $email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 
 
\t \t 
 
\t \t if(!preg_match($email_exp,$email)) 
 
\t \t { 
 
\t \t \t $errors ['email']= '<b>The email you entered does not appear to be valid</b></br>'; 
 
\t \t } 
 
\t } 
 

 
\t if (empty($_POST['phone_number'])){ 
 
\t \t $errors['phone_number'] = 'Phone number is required.'; 
 
\t } else{ 
 
\t \t $phone_number_exp ='/^[0-9]{5,12}$/'; 
 
\t \t if(!preg_match($phone_number_exp, $phone)) 
 
\t \t { 
 
\t \t $errors ['phone_number']='<b>Phone number entered is invalid</b></br>'; 
 
\t \t } \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
\t } 
 
\t if (empty($_POST['message'])){ 
 
\t \t $errors['message'] = 'Message is required.'; 
 
\t } 
 

 
// return a response =========================================================== 
 

 
\t // if there are any errors in our errors array, return a success boolean of false 
 
\t if (! empty($errors)) { 
 

 
\t \t // if there are items in our errors array, return those errors 
 
\t \t $data['success'] = false ; 
 
\t \t $data['errors'] = $errors ; \t 
 
\t } else 
 
\t { 
 

 
\t \t // success processing 
 

 

 
//connecting to the db 
 

 
$dbhost = 'localhost'; \t \t 
 
$dbuser = 'root'; 
 
$dbpass = ''; 
 
$db = '1'; 
 

 
$dbconn = mysql_connect($dbhost, $dbuser, $dbpass); 
 
mysql_select_db($db); 
 

 
$query = ("INSERT INTO user (name, email, phone_number, message) VALUES ('$name','$email','$phone','$message')"); 
 
mysql_query($query); \t 
 
\t \t 
 
\t  { 
 
\t \t \t \t $data['1'] = false; 
 
\t \t \t } 
 
// email sent from gmail client id = --- 
 
$email_to="---"; 
 
$email_subject="Lead Form"; 
 
$msg = "Form details from interested customer:\n\n"; 
 
\t 
 
\t function clean($string) 
 
\t { 
 
\t \t $sickstring = array("content-type","bcc:","to:","cc:","href"); 
 
\t \t return str_replace($sickstring,"-",$string); 
 
\t \t //replaces any characters found in the array with a "-". 
 
\t } 
 
\t \t $msg .= "Email: ".clean($email)."\n"; 
 
\t  $msg .= "Phone Number: ".clean($phone)."\n"; 
 
\t \t $msg .= "Name: ".clean($name)."\n"; 
 
\t \t $msg .= "Message: " . ($message)."\n"; 
 

 
\t /* if using the name variable 
 
\t $message .= "name: ".clean($name)."\n"; */ 
 
\t 
 
\t //header for email.. variable not working , check variable on thursday .. 
 
\t 
 
\t $headers = "From: " . ($email) . "\r\n". 
 
\t "Reply_To: " . ($email) . "\r\n". 
 
\t "xmailer: php/" . phpversion(); 
 
\t 
 
\t @mail($email_to, $email_subject, $msg, $headers); 
 

 
\t $data['success'] = true; 
 
\t $data['message'] = 'Success!'; 
 
\t 
 
\t }// return all our data to an AJAX call 
 
\t echo json_encode($data);
<form action="process.php" method="POST" id="ezform"> 
 
    
 
     
 
     <!-- NAME --> 
 
     <div id="name-group" class="form-group"> 
 
      <label for="name">Name</label> 
 
      <input type="text" class="form-control" name="name" placeholder="Name"> 
 
      
 
     </div> 
 

 
     <!-- EMAIL --> 
 
     <div id="email-group" class="form-group"> 
 
      <label for="email">Email</label> 
 
      <input type="text" class="form-control" name="email" placeholder="[email protected]"> 
 
      
 
     </div> 
 

 
     <!-- NUMBER --> 
 
     <div id="phone_number-group" class="form-group"> 
 
      <label for="phone_number">Phone Number</label> 
 
      <input type="text" class="form-control" name="phone_number" placeholder="Number"> 
 
      
 
     </div> 
 
     <!--MESSAGE--> 
 
     <div id="message-group" class="form-group"> 
 
      <label for="message">Message</label> 
 
      <input type="text" class="form-control" name="message" placeholder="Your Message"> 
 
      
 
     </div> 
 
     <div id="Demo-BS" style="padding:30px;"> 
 
    <button type="submit" class="btn btn-default">Submit</button> 
 
    </div> 
 

 
    </form>

+3

をエスケープするhtmlentitiesを使用する必要がありますので、** WARNING **あなたは、テキストエリアを使用しているものの:あなただけのPHPを学習している場合は、[ 'するmysql_queryを使用しないでください'](http://php.net/manual/en/function.mysql-query.php)インターフェイス。それはPHP 7で削除されたのでとてもひどいと危険です。[PDOのようなものは学ぶのが難しくない](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps -pdo-for-database-access /)と[PHP The Right Way](http://www.phptherightway.com/)のようなガイドがベストプラクティスを説明しています。あなたのユーザーデータは**適切にエスケープされていません**(http://bobby-tables.com/php.html)、[SQLインジェクションバグ](http://bobby-tables.com/)があります。悪用される。 – tadman

+0

データを正しくエスケープしていないし、廃止されたAPIを使用しています。改行はこの取り決めで問題になるだろう。 – tadman

+0

フルPHPとHTMLコードを追加できますか?私が見ることができるように、入力は1つしかなく、それは4であると言っています。 – Akshay

答えて

0

あなたが書かれているクエリの上にこのコードを追加します。

$message = htmlentities($message); 

あなたがHTML文字

関連する問題