Having some problems and can't figure out why for the life of me, $name = mysql_real_escape_string($_POST['add_name']); $series = mysql_real_escape_string($_POST['add_series']); $query = "SELECT * from `releases` WHERE name='$name' AND series='$series'"; $result = mysql_query($query); $num_rows = mysql_num_rows($result); while ($row = mysql_fetch_object($result)){ $queue_status = $row->modqueue; } if ($num_rows != 0) { if ($queue_status == 1) { mserror("Already submitted, pending review."); } else { mserror("Already exists in our database."); } } PHP: This little snippet is running on a submission form for a certain project. The problem I'm having is it's being bypassed when I have the AND series='$series' clause. There is a series field on the table, it's INT(13), and my script completely ignores the rules I've set despite everything looking ok from my end. My form is set up properly as well because it IS saving the right variable for series into the table on an INSERT query that follows this. mserror is my error function that is supposed to print the message and then exit();, it's working properly in other sections of the script. Anything I'm missing? edit: I debugged and found this is the error it's spitting out:
Better check $series, is not correct i think. Also use intval() for int values (AND series='".intval($series)."'"
Usually when i'm having issues like this, i echo "query" statement, copy it and paste it into phpmyadmin and try to see what errors are. Then i generate with phpmyadmin a valid query statement using same fields/criteria and compare the two statements what is different and how should i modify the original query to make them look and behave the same.
Fixed! I played around in phpMyAdmin and changing series to `series` on the query has done the trick. Thanks hogan_h, and everyone else.
Well then just so you understand this if you do not. I imagine series is actually a reserved sql word as a result when you put series it's thinking something else. So using ` around it tells it that it's not the reserved word series which is probably a sql function of some kind.