嘿傢伙有點麻煩在這裏,我不明白爲什麼我的PHP腳本不工作。
因此,我將首先顯示的代碼,然後走了過來,我遇到的問題:
include('select-stock.php');
include('db-affinity/header-main.php'); ?>
<?php $carId = $_GET['id']; ?>
<?php
try {
$carview = $db->prepare("SELECT Make, Model, Colour, FuelType, Year, Mileage, Bodytype, Doors, Variant, EngineSize, Price, Transmission, PictureRefs, ServiceHistory, PreviousOwners, Options, FourWheelDrive, FullRegistration FROM import WHERE FullRegistration = $carId");
} catch (Exception $e) {
echo "Error.";
exit;
}
$cardata = $carview->fetch(PDO::FETCH_ASSOC)
?>
<div class="container">
<div class="row">
<div class="col-md-12 col-sm-12">
<?php echo "$carId"; ?>
<?php echo mysql_errno($carview) ?>
<?php echo '<ul class="overwrite-btstrp-ul other-specs-ul h4-style">
<li>Mileage: '.number_format($cardata["Mileage"]).'</li>
<li>Engine size: '.$cardata["EngineSize"].'cc</li>
</ul>'
?>
</div>
</div>
</div>
<?php include('db-affinity/footer.php') ?>
所以基本上我想從這個代碼實現的是,如果基於上給我的網頁動態內容一個URL的?id=
與我的'FullRegistration'
列的一行匹配。
因此,例如,如果我有一個像這樣的網址「www.cars.com/carview.php?id=NG61CWJ」,那麼我希望我的腳本檢查是否有一行在'FullRegistration'列中有該值我的表,然後現在在我的代碼回聲出該行的某些列的結果,像這樣的例子:
<?php echo '<ul class="overwrite-btstrp-ul other-specs-ul h4-style">
<li>Mileage: '.number_format($cardata["Mileage"]).'</li>
<li>Engine size: '.$cardata["EngineSize"].'cc</li>
</ul>'
?>
理論上
FROM import WHERE FullRegistration = $carId
應但是,對於我的服務器上的一些原因,這種情況發生當我使用上面的腳本時,我得到了零結果而不是ro的結果W¯¯的GET ID相匹配,我得到:
里程:0 發動機尺寸:CC
我知道我的代碼是目前不安全但它是不是在這個時刻的問題。
任何想法,爲什麼我可能會得到零結果返回,我對這張表的其他查詢工作完美無瑕,但是我有這個麻煩,你能看到這個代碼中可能會導致這個問題的任何東西?
下面是包含在代碼塊選擇-stock.php頂端的其他查詢,以防萬一這可能是一個有點問題:
<?php
include('database.php');
try {
$results = $db->query("SELECT Make, Model, Colour, FuelType, Year, Mileage, Bodytype, Doors, Variant, EngineSize, Price, Transmission, PictureRefs, ServiceHistory, PreviousOwners, Options, FourWheelDrive, FullRegistration FROM import ORDER BY Make ASC");
} catch (Exception $e) {
echo "Error.";
exit;
}
///carousel-vehicle results
try {
$fourresults = $db->query("SELECT Make, Model, Colour, FuelType, Year, Mileage, Bodytype, Doors, Variant, EngineSize, Price, Transmission, PictureRefs, ServiceHistory, PreviousOwners, Options, FourWheelDrive FROM import ORDER BY Make LIMIT 0, 4");
} catch (Exception $e) {
echo "Error.";
exit;
}
try {
$fourresultsone = $db->query("SELECT Make, Model, Colour, FuelType, Year, Mileage, Bodytype, Doors, Variant, EngineSize, Price, Transmission, PictureRefs, ServiceHistory, PreviousOwners, Options, FourWheelDrive FROM import ORDER BY Make LIMIT 4, 4");
} catch (Exception $e) {
echo "Error.";
exit;
}
try {
$fourresultstwo = $db->query("SELECT Make, Model, Colour, FuelType, Year, Mileage, Bodytype, Doors, Variant, EngineSize, Price, Transmission, PictureRefs, ServiceHistory, PreviousOwners, Options, FourWheelDrive FROM import ORDER BY Make LIMIT 8, 4");
} catch (Exception $e) {
echo "Error.";
exit;
}
try {
$makeFilter = $db->query("SELECT DISTINCT Make FROM import ORDER BY Make ASC");
} catch (Exception $e) {
echo "Error.";
exit;
}
try {
$modelFilter = $db->query("SELECT DISTINCT Model FROM import ORDER BY Make ASC");
} catch (Exception $e) {
echo "Error.";
exit;
}
?>
所有這些疑問都工作無瑕的活網站上,所以數據庫連接顯然工作。