Hi there I have a website which takes in a Car brand and generates a Car Id result which corresponds to a database. Although there are many solutions available for storing a sql query result to a variable but in this case it does not seem to work.
I have already tried the sql statement in the database and it works with 1 result output which is right.
<?php
session_start();
include "dbconn.php";
$carcat = $_SESSION['selectedcarcat'];
$carbrand = $_POST['carbrand'];
$userid = $_SESSION['loginid'];
$username = $_SESSION['loginname'];
$startdate = $_POST['date1'];
$enddate = $_POST['date2'];
$pick = $_POST['pickuploc'];
$return = $_POST['returnloc'];
$calqty = 0;
$selcaridsql = "SELECT carid FROM cars WHERE brand='$carbrand' ";
$caridresult = $dbcnx->query($selcaridsql);
$caridrow = mysql_fetch_object($caridresult);
$carid = $caridrow['carid'];
if (!$caridresult)
{
$errmessage = "Your carid select query failed.";
echo "<script type='text/javascript'>alert('$errmessage');</script>";
}
echo '<br>Debug 1 ';
echo '<br>The selected qty is '
.$qtyresult1.'<br />';
echo '<br>The calculated qty is '
.$calqty.'<br />';
echo '<br>The content carid is '
.$carid.'<br />';
echo '<br>The content userid is '
.$userid.'<br />';
echo '<br>The content start is '
.$startdate.'<br />';
echo '<br>The content end is '
.$enddate.'<br />';
echo '<br>The content pick is '
.$pick.'<br />';
echo '<br>The content return is '
.$return.'<br />';
echo '<br>The content carbrand is '
.$carbrand.'<br />';
?>
The error occurs with a blank result shown at the "Content carid is". After going through the forums it seems that the variable $carid
has no value which I may have inferred wrongly.
The echo results:
Debug 1
The selected qty is
The calculated qty is 0
The content carid is
The content userid is
The content start is 2016-10-28
The content end is 2016-10-29
The content pick is jurong
The content return is bishan
The content carbrand is Honda
</div>