2017-08-31 6 views
-5

私は非常に基本的な何かを間違っているようです。比較したい簡単なプログラムは失敗します。なぜこれが正しく比較されないのですか

いくつかの質問:あなたが喜ばせるために 1.リクエストは、私は比較にここで間違っているものを見つけるのを助けることが第一条件とプリント空白 2に行くを続けているが、私はdatetimepicker1

の値をピックアップすることはできませんよ

助けてください!

<?php 

    $name = trim(stripslashes($_REQUEST['name'])); 
    $email = trim(stripslashes($_REQUEST['email'])); 
    $phone = trim(stripslashes($_REQUEST['phone'])); 
    $city = trim(stripslashes($_REQUEST['city'])); 
    $datetimepicker1 = trim(stripslashes($_REQUEST['datetimepicker1'])); 
    $placeofbirth = trim(stripslashes($_REQUEST['placeofbirth'])); 
    $message = trim(stripslashes($_REQUEST['message'])); 

    $response = ''; 
    $result = -100; 


    //conection: 
    $link = mysqli_connect("localhost","admin","[email protected]","graph") or die("Error " . mysqli_error($link)); 

    //consultation: 
    $query = "INSERT INTO user_msg 
        (user_msg_name, user_msg_email, user_msg_phone, 
        user_msg_city, user_msg_dob, user_msg_birthtime,  
        user_msg_birthplace, user_msg_messages, 
        user_msg_section) 
       values ('$name','$email','$phone', 
         '$city', '$datetimepicker1', '$datetimepicker1', 
         '$placeofbirth', '$message', 'contactus')" ; 

    //execute the query. 
    $result = $link->query($query) or die("Error in the consult.." . mysqli_error($link)); 

    //display information: 
    if($result == -100) 
    { 
     $response = ' '; 
    } 
    elseif($result > 0) 
    { 
     $response = "Thank you $fname $lname for contacting us!<br/>"; 
    } 
    else 
    { 
     $response = "Sorry, there has been an error, please try later.<br/>"; 
    } 

    echo ' response='.$response; 
?> 
+5

あなたはSQLインジェクションのために広くオープンしています。 mysqliを使用しているので、[prepared statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)と[bind_param](http://php.net/ manual/en/mysqli-stmt.bind-param.php)。 **これは発生する可能性のある厄介な引用問題を処理します。** – aynber

+5

INSERTクエリの結果は 'TRUE'または' FALSE'になります。したがって、 'if($ result == -100)'は完全なナンセンス – RiggsFolly

+0

ですin $ query - 変数(引用符で囲まれた変数)のような文字列に変数を貼り付けることはできません。変数$ nameや文字列 '$ name'の値が欲しいかどうか、どうしたら分かりますか? – johnyTee

答えて

0

お手数ですが、@RiggsFollyありがとうございます。

はい、戻り値としてtrueとfalseを指定していました。私は間違った方向を指していた。 であり、$ result = -100を定義する必要はありませんでした。実際に私はこれを私のフォームの1つに使ってみることにしていて、そこでいくつかの基本的な間違いをしました。

非常によく働いた。

if ($result === TRUE) { 
    $response = "Thanks for connected with us. We'll get in touch with you soon!!"; 
} else { 
    $response = "Error: " . $sql . "<br>" . $conn->error; 
} 

とにかく、お世話になりました。

関連する問題