私はPHPとMySQLに取り組んでいます。私は選択されたユーザーの番号と住所を表示したい。私は別のページからAJAXを使用しました。私のクエリは正常に動作します。選択したユーザーのデータを表示できます。AJAX呼び出しでHTMLのデザインが変更されますか?
しかし、問題は私が右のラベルにないデータだユーザーを選択するときです。私はあなたにそれがどのように見えるか、そしてこれについてあなたに私のコードを示します。ドロップダウンから選択した後
:ドロップダウンから選択する前に
前のデータを提出するための私のコード:AJAX呼び出しの後
<div style="margin-bottom: 3%;" class="col-md-12">
<div class="col-md-6" style="margin-top: -2%;">
<label>GSTIN</label>
<label name="gstn" class="control-label" value="" id="state-list1">
</div>
</div>
<div style="margin-bottom: 3%;" class="col-md-12">
<div class="col-md-5" style="margin-top: -5%;">
<label>Billing Address</label>
<label name="billingAddress" id="state-list" class="control-label demoInputBox" value="">
</div>
</div>
コード:012 AJAX呼び出しのための
<?php
if (!empty($_POST['customer_name']))
{
$query = mysqli_query($conn,"SELECT customer_locations.address , customer_locations.state ,customer_locations.custLocId, customer_locations.city , customer_locations.pin , customer_locations.locality, customer_locations.gstNo ,customer_master.defaultBilling , customer_master.defaultsupply FROM customer_locations INNER JOIN customer_master ON customer_locations.customerId = customer_master.customerId WHERE customer_master.customerId = '" . $_POST["customer_name"] . "'");
?>
<?php
while ($row = mysqli_fetch_array($query)) {
?>
<label value="<?php echo $row["custLocId"];?>"><?php echo $row['gstNo'];?></label><br>
<?php }}?>
<?php
if (!empty($_POST['customer_name']))
{ $query = mysqli_query($conn,"SELECT customer_locations.address , customer_locations.state , customer_locations.custLocId ,customer_locations.city , customer_locations.pin , customer_locations.locality, customer_locations.gstNo ,customer_master.defaultBilling , customer_master.defaultsupply FROM customer_locations INNER JOIN customer_master ON customer_locations.customerId = customer_master.customerId WHERE customer_master.customerId = '" . $_POST["customer_name"] . "'");
?>
<?php
while ($row = mysqli_fetch_array($query)) {
?><label value="<?php echo $row["custLocId"];?>"><?php echo $row['defaultBilling'];?></label>
<?php }}?>
スクリプト:あなたはAjax呼び出しAJAX呼び出し
ため<?php
if (!empty($_POST['customer_name']))
{
// For escaping special characters
$customer_name = mysql_real_escape_string($_POST["customer_name"]);
$query = mysqli_query($conn,"SELECT customer_locations.address , customer_locations.state ,customer_locations.custLocId, customer_locations.city , customer_locations.pin , customer_locations.locality, customer_locations.gstNo ,customer_master.defaultBilling , customer_master.defaultsupply
FROM customer_locations INNER JOIN customer_master ON customer_locations.customerId = customer_master.customerId
WHERE customer_master.customerId = '" . $customer_name . "'");
// Since we only fetch a single users data we dont need to use while loop
$row = mysqli_fetch_array($query);
$data=array(
'custLocId'=>$row["custLocId"],
'gstNo'=>$row['gstNo'],
'defaultBilling'=>$row['defaultBilling']
);
header("Content-type:application/json");
echo json_encode($data);
}
?>
スクリプトで
</label>
あなたのコードはSQLインジェクション攻撃に対して脆弱です。あなた自身をより良く保護するために、準備されたステートメントとmysqliでパラメータ化されたクエリを使用する方法をGoogleに教えてください。現時点では、ユーザーがデータを盗み出したり、破損したり、削除したりする可能性のある悪意のある値(顧客名など)を送信することで、コードのハッキングが広く行われます。 – ADyson
初心者の方には、AJAX Callの返信から返ってくる実際のHTMLはどうですか? – TimBrownlaw
@amitここでは、ajaxページからGstnとBillingアドレスを一緒に出力し、divコンテンツ全体を置換する必要があります。または、コンテンツタイプjsonの出力を使用し、必要なhtmlフィールドのみを入力する必要があります。 –