Richzilla Posted July 18, 2007 Share Posted July 18, 2007 Hi All. I'm trying to stop my file upload system adding the same files to my database. The script below is a much simplified version of what I'm using. It's getting frustrating as I can't get this to work. I have a page previosu to this that posts up the details form a previous form. The form and everything works fine apart from the duplicate check. <? $event = @$_POST['event']; $date = @$_POST['date']; $flyer = @$_POST['uploaded']; $user="xxxxx"; $pass="xxxxxx $host = "xxxxx"; $dbase="xxxxx"; $table = "events"; mysql_connect($host,$user,$pass); @mysql_select_db($dbase) or die("Unable to select database"); $query = "SELECT FROM events WHERE event ='$event'"; $result = mysql_query($query); if ($result !== FALSE){ echo "Error : This event is already in the database"; } else { echo "This is a new event"; } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted July 18, 2007 Share Posted July 18, 2007 <?php $query = "SELECT FROM events WHERE event ='$event'"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { echo "Error : This event is already in the database"; } else { // not found } ?> Quote Link to comment Share on other sites More sharing options...
drewbee Posted July 18, 2007 Share Posted July 18, 2007 $result will always be true regardless of the rows returned. It will only be false if the query fails. You want to use mysql_num_rows() <? if (mysql_num_rows($result) > 0) { echo "Error: This event is already in the database"; } else { echo "This is a new event"; } ?> Quote Link to comment Share on other sites More sharing options...
Richzilla Posted July 18, 2007 Author Share Posted July 18, 2007 thanks for the quick responses, sadly the first response has a syntax error where there's a missing } closing the first statement. The second code causes this error - Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource Quote Link to comment Share on other sites More sharing options...
clanstyles Posted July 18, 2007 Share Posted July 18, 2007 That type of crap happens when the query is wrong usually. <?php $query = "SELECT * FROM events WHERE event ='$event'"; if ($result = mysql_query($query) or die(mysql_error()) > 0) { if (mysql_num_rows($result)) { echo "Error : This event is already in the database"; } else { echo "Not Found"; } } ?> Fixed the thinkgs u needed try that. Quote Link to comment Share on other sites More sharing options...
drewbee Posted July 18, 2007 Share Posted July 18, 2007 Yeah. My code works just fine. Your SQL Statement is incorrect. Quote Link to comment Share on other sites More sharing options...
Richzilla Posted July 18, 2007 Author Share Posted July 18, 2007 That type of crap happens when the query is wrong usually. <?php $query = "SELECT * FROM events WHERE event ='$event'"; if ($result = mysql_query($query) or die(mysql_error()) > 0) { if (mysql_num_rows($result)) { echo "Error : This event is already in the database"; } else { echo "Not Found"; } } ?> Fixed the thinkgs u needed try that. Top stuff works a treat. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.