2017-12-16 5 views
-1

私は今、自分の電子メールと別のユーザの電子メールを入力してテーブルに「友人」として追加できるコードを作成中です"friends"成功したクエリが表示されずにフォームデータがまだDBに送信されている

これまでのところ私のコードは、フォームデータをDB /テーブルの "friends"に投稿するという点では機能していますが、表示したいメッセージはまったく表示されません。

私のHTMLフォーム:

<form class="form-signin" action="FriendLookup.php" method = "POST" enctype="multipart/form-data"> 
     <h2 class="form-signin-heading">Add a Friend</h2> 
     </br> 
     <label for="inputEmail" class="sr-only">Your Email</label> 
     <input type="text" id="inputEmail1" name = "self_email" class="form-control" placeholder="Friend's Username" > 
     </br> 
     <label class="sr-only">Your Friend's Email</label> 
     <input type="text" id="inputEmail2" name = "friend_email" class="form-control" placeholder="Your Username" > 
     </br> 
     <button class="btn btn-lg btn-primary btn-block" name = "submit" type="submit">Search</button> 
     </form> 

PHPスクリプト:

<?php 
include_once('support.php'); 
//connect_database.php contains your connection/creation of a PDO to connect to your MYSQL db on bmgt406.rhsmith.umd.edu/phpmyadmin 
include_once('connect_database.php'); 
ini_set("display_errors","1"); 
error_reporting(E_ALL); 

// Initialize $title and $body. 
$title = "Add User"; 
$body = "<fieldset><legend> $title </legend>"; 


$name_of_table = "friends"; 



// Check if the table exists in the db. 
if (tableExists($db, $name_of_table)) { 

    $inputemail1 = $_POST['self_email']; 
    $inputemail2 = $_POST['friend_email']; 

     // Prepare a SQL query and bind all 6 variables. 
     $sqlQuery = "INSERT INTO $name_of_table (self_email, friend_email) 
     VALUES (:self_email, :friend_email)"; 



     $statement1 = $db->prepare($sqlQuery); 

     $statement1->bindValue(':self_email', $inputemail1, PDO::PARAM_STR); 
     $statement1->bindValue(':friend_email', $inputemail2, PDO::PARAM_STR); 


     // Execute the SQL query using $statement1->execute(); and assign the value 
     // that is returned to $result. 
     $result = $statement1->execute(); 

     if(!$result) { 
       // Query fails. 
       $body .= "Inserting entry for friend failed."; 
     } else { 
       // Query is successful. 
        $body .= "Success"; 
     } 


     // Closing query connection 
       $statement1->closeCursor(); 

      } 



$body .= "</fieldset>"; 
echo generatePage($title,$body); 
?> 

すべてのヘルプは大歓迎です。私は初心者プログラマーです。

+2

呼び出しているgeneratePageメソッドはどこにありますか? –

+0

前の質問のステータスはどうですか? –

+0

関数generatePage($ title、$ body){ $ page = <<< EOPAGE EOPAGE; return $ page; } ?> –

答えて

-1

私の関数generatePageが間違っていました。私は関数にHTMLを追加し、今は動作します!

関連する問題