içinde sakla. Bir sql sorgusundaki sonucu php sorgumda bir değişkene kaydetmeye çalışıyorum. Ama bir şey, işe yaramıyor, çünkü ben okul çocuğu hatalarını yapıyorum ve php'deki deneyimsizliğim yüzünden. registrationno ve driverNo hem hem sonra sonuç 0 kayıtları döndürür ya benzersiz (bulunamadı) gibiİlk sonuç değerini sql sorgusundaki bir değişkene php
<?php
include "init.php"
if(!empty($_POST['driverNo'])){
$driverNoText = $_POST['driverNo'];
$stmt = "SELECT registrationNo FROM cars WHERE driverNo = ?";
$result = $conn->prepare($stmt);
$result->bind_param('s', $driverNoText);
$result->execute();
$result->store_result();
if($result->num_rows > 0){
$registrationNo = $result["registrationNo"];
echo $registrationNo;
}
else{
$registrationNo = "";
}
}
else{
echo "Something went horribly wrong";
}
?>
unutmayınız VEYA sadece 1 (bulunan):
Bu benim kodudur.
Sadece kayıt işlemini $ registrationNo içine kaydetmek istiyorum, çünkü bu değeri daha sonra başka bir yerde kullanmam gerekiyor. sizin örnekte ->store_result()
kullanılmasıdır
$result = $conn->prepare($stmt);
$result->bind_param('s', $driverNoText);
$result->execute();
$result->store_result();
$result->bind_result($registrationNo);
while($result->fetch())
{
echo $registrationNo;
}
$result->free_result();
Not olduğunu: Birisi bana hata
Teşekkür
Bunun için->bind_result()
kullanmak zorunda
Bu * tam * şifre mi okuyun veya '$ conn' ilan nereye ihmal etmedi? – Aleeeeee
$ conn, init.php dosyasından. Bu, –
numaralı bağlantıdır. Sorun, $ registrationNo = $ result ["registrationNo"] satırında yatar; –