I wrote a function in php which updates a mysql-table according to a given array. Before updating, I check whether there already exists an entry with the same ‚description‘-value.
// $fachtyp is given by foreach
$query = "SELECT IF(EXISTS(SELECT 1 FROM fachtyp WHERE `Description`='$fachtyp'),'true','false')"
. " AS existance";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_assoc($result);
$exists = ($row['existance'] === 'true');
if (!$exists) { /* update */ }
The problemis as follows: When I debugged this, i recognised $row['exists'] to be twhile debugging) to return 'false' in netbeans. How can this happen??
Thx fer reply, Lukas
mysqli
you should be using parameterized queries andbind_param
to add user data to your query. Never use string interpolation to accomplish this. – tadman Sep 12 '13 at 18:43'true'
as a string. Try replacing it with == true (with out quotes)? – Ofir Baruch Sep 12 '13 at 18:43SELECT 1 ...
and act accordingly? – Ivan Hušnjak Sep 12 '13 at 18:45var_dump($row);
to see what actually is returned as result? – Ivan Hušnjak Sep 12 '13 at 18:49