I just want to check and see if a row exists where the $lectureName shows. If a row does exist with the $lectureName somewhere in it, I want the function to return "assigned" if not then it should return "available". Here's what I have. I'm fairly sure its a mess. Please help.
function checkLectureStatus($lectureName) { $con = connectvar(); mysql_select_db("mydatabase", $con); $result = mysql_query("SELECT * FROM preditors_assigned WHERE lecture_name='$lectureName'"); while($row = mysql_fetch_array($result)); { if (!$row[$lectureName] == $lectureName) { mysql_close($con); return "Available"; } else { mysql_close($con); return "Assigned"; } }
When I do this everything return available, even when it should return assigned.
Easiest way to check if a row exists:
$lectureName = mysql_real_escape_string($lectureName); // SECURITY! $result = mysql_query("SELECT 1 FROM preditors_assigned WHERE lecture_name='$lectureName' LIMIT 1"); if (mysql_fetch_row($result)) { return 'Assigned'; } else { return 'Available'; }
No need to mess with arrays and field names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With