Php mysql查询中的变量
大家好,我这里的问题是,如果将$vehicle插入数据库查询$vquery=mysql_querySELECT*FROM vehicletbl,其中vehicle='$vehicle1',则$vehicle不会返回其值;但如果它被回响,它将返回其值。这里的逻辑是,它将从VehicleBL中选择所有值,“vehicle”列中任何值的值都将等于$vehicle1。谢谢你的帮助 您的查询没有错误处理。尝试向查询调用添加一些调试:Php mysql查询中的变量,php,Php,大家好,我这里的问题是,如果将$vehicle插入数据库查询$vquery=mysql_querySELECT*FROM vehicletbl,其中vehicle='$vehicle1',则$vehicle不会返回其值;但如果它被回响,它将返回其值。这里的逻辑是,它将从VehicleBL中选择所有值,“vehicle”列中任何值的值都将等于$vehicle1。谢谢你的帮助 您的查询没有错误处理。尝试向查询调用添加一些调试: for ($i=0; $i<$count; $i++) {
for ($i=0; $i<$count; $i++) {
$appid = $chk[$i];
include "dbconnect.php";
$selectquery = mysql_query("SELECT * FROM regform_admin WHERE tid = '$appid'");
$fetch = mysql_fetch_array($selectquery);
$tid = $fetch['tid']; $username = $fetch['username']; $c_month = $fetch['month']; $c_day =$fetch['day']; $c_year = $fetch['year'];
$c_month2 = $fetch['month2']; $c_day2 =$fetch['day2']; $c_year2 = $fetch['year2'];
$pickup = "".$c_month."/".$c_day."/".$c_year."";
$return = "".$c_month2."/".$c_day2."/".$c_year2."";
$pickuploc = "".$fetch['pickupret']." "." ".$fetch['speclocation']."";
$desti = "".$fetch['destination']." "." ".$fetch['location']."";
$vehicle1 = $fetch['vehicle1'];
$datesent = date("n j, Y; G:i"); ;
$rand = rand(98765432,23456789);
include "vehicledbconnect.php";
$vquery = mysql_query("SELECT * FROM vehicletbl WHERE vehicle = '$vehicle1'");
$getvquery = mysql_fetch_array($vquery);
$maxcars = $getvquery['maxcars'];
$carsleft = $getvquery['carsleft'];
if ($carsleft == 0) {
echo '
<script language="JavaScript">
alert("Cannot move reservation to Pending for payment status. No available vehicles left for this reservation.");
</script>';
echo "$vehicle1";
}
代码的其余部分很难看,但看起来还行,所以开始看看为什么您没有从查询中得到任何东西
永远不要假设查询成功。尝试以下方法进行调试:
$result = mysql_query(...) or die(mysql_error());
这就是我在sql中查找错误的方法。Noob程序员?以下是一些需要知道的事情:
$sql = "SELECT * FROM vehicletbl WHERE vehicle = '" . $vehicle1 . "'";
$vquery = mysql_query($sql) or die(mysql_error() . "\n<br>$sql");
安全和安保:
$desti = "".$fetch['destination']." "." ".$fetch['location']."";
// WHY ?? Isn't that easier to do this ?
$desti = $fetch['destination']." ".$fetch['location'];
还有其他的评论,但是首先尝试改进这些观点 没有按名称$vehicle分配任何变量?请显示$query OutputsHanks和yes的内容。代码的其余部分很难看。那是因为我还是一个noob程序员。
// Include the file before the loop ! You're including 20 times your file, but you just need to do it once ! Another thing to know:
include_once("dbconnect.php");
$desti = "".$fetch['destination']." "." ".$fetch['location']."";
// WHY ?? Isn't that easier to do this ?
$desti = $fetch['destination']." ".$fetch['location'];
// Don't forget to escape your variables before putting it in mysql queries
$appid = mysql_real_escape_string($appid);
$selectquery = mysql_query("SELECT * FROM regform_admin WHERE tid = '$appid'");