-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;
?>
あなたは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
INSERTクエリの結果は 'TRUE'または' FALSE'になります。したがって、 'if($ result == -100)'は完全なナンセンス – RiggsFolly
ですin $ query - 変数(引用符で囲まれた変数)のような文字列に変数を貼り付けることはできません。変数$ nameや文字列 '$ name'の値が欲しいかどうか、どうしたら分かりますか? – johnyTee