$paid = $row ['datepaid'];
}
echo 'Paid ='.$paid.'!';
if ($privlink=='')
{
if ($paid=='')
{
Option A }
else
{
Option B }
}
$paid is a variable set by contents of a mysql DB - which I am using to decide with PDF to output. The echo statment is purely to debug by outputting the value of $paid. the output from this echo was
‘Paid =!’
Therefore making me believe that $paid has no value.
Why is it then that my if statment is acting as if $paid has a value, or at least is not equal to nothing.
Can someone please enlightment me.
(i’d like the following to work - If $paid = ‘’ then option A else option B)
Ok well what I’d recommend is a little restructure. Also your query quotes are a little messed up so I’ll fix that for you, which may resolve your issue of getting a null result too.
As it appears that you are only expecting one row, the while loop needn’t be used. Try the following:
$sql = "SELECT privlinkid, datepaid FROM property INNER JOIN invoice ON invoice.id = property.id WHERE property.id = '{$id}'"; //Capitalising the query's commands is a good practise because it helps your eyes separate the commands from the other stuff. Also, if the ID is an integer, remove the single quotes around it and cast the id to an integer before the query using: $id = (int)$id; - this will prevent SQL injection attacks if you haven't prevented them beforehand.
$result = mysqli_query($link, $sql);
if($result === false){
$error = 'Error - Please enter a valid Property ID. ' . mysqli_error($link);
include 'error.html.php';
exit;
}
$fetch = mysqli_fetch_array($result);
if($fetch === false){ //The first row is false, therefore non-existent, therefore no rows have been returned. Look into the fetch_array function to see why this works.
//do whatever you need to do if no results are returned:
}else{
$privlink = $fetch['privlinkid'];
$paid = $fetch['datepaid'];
echo '<ul>';
echo '<li>Paid: ' . $paid . '</li>'; //exclamation marks are fun and all, but not generally appropriate.
echo '<li>PrivlinkID: ' . $privlink . '</li>';
echo '</ul>';
}
Thanks for your replies Jake, and in a round about way it worked, as well as giving me some solid advise in the process thank you!
Your advise regarding the use of var_dump’s helped trememdeously, allowed me to isolate the fact I had neglected to set $id (or rather get and sanitise from the code on button press!)
Strangely
SELECT privlinkid, datepaid FROM property INNER JOIN invoice ON invoice.id = property.id WHERE property.id = NULL
didnt return any values, let alone the one i wanted!!! - head hangin in shame now!