bineye Posted October 24, 2013 Share Posted October 24, 2013 Been away from this for months but needed to make a quick script for something and been tripped up on day 1 stuff. Anyone know why this would be constantly showing up as a positive match? I want it to fail and give the error message if all 4 numbers match another entry with those exact same 4 numbers. Even if only 3 numbers of 4 match, the script should progress, but its always showing a match. I know its something simple, just can't see it :s $q=mysql_query("SELECT * FROM tickets WHERE name='{$_POST['name']}'"); while($c=mysql_fetch_assoc($q)) { if(($_POST['no1'] == $c['no1'] || $c['no2'] || $c['no3'] || $c['no4']) && ($_POST['no2'] == $c['no1'] || $c['no2'] || $c['no3'] || $c['no4']) && ($_POST['no3'] == $c['no1'] || $c['no2'] || $c['no3'] || $c['no4']) && ($_POST['no4'] == $c['no1'] || $c['no2'] || $c['no3'] || $c['no4'])) { echo "This ticket already exists.<br><a href='add.php'>Back</a>"; exit; } } Quote Link to comment Share on other sites More sharing options...
sniko Posted October 24, 2013 Share Posted October 24, 2013 (edited) Um, try this: $q=mysql_query("SELECT * FROM tickets WHERE name='{$_POST['name']}'"); while($c=mysql_fetch_assoc($q)) { if( in_array($_POST['no1'], array_values($c)) AND in_array($_POST['no2'], array_values($c)) AND in_array($_POST['c3'], array_values($c)) AND in_array($_POST['no4'], array_values($c)) { echo "This ticket already exists. <a href='add.php'>Back</a>"; break; } } Edited October 26, 2013 by sniko Quote Link to comment Share on other sites More sharing options...
bineye Posted October 25, 2013 Author Share Posted October 25, 2013 Um, try this: Thanks sniko, forgotten how to array properly so went the long way around. Been too long away :s Anyway, worked 100% cheers :D Quote Link to comment Share on other sites More sharing options...
Lucifer.iix Posted November 18, 2013 Share Posted November 18, 2013 @Bineye: Why do you want to do this ? Let the DB deside this: if Query: INSERT ..... INTO TICKETS gives a key error saying the key already exists. Than you know. Also you can just say: "Insert this if not exists, but UPDATE if doesn exists" Now your doing a SELECT statement that will echo some text, and does nothing... Just make code that does SOMETHING (hopefully logical) and if that doesn't work for some reason like: "Ticket already exists". Throw a exception, like Throw New TicketProblem(SQL_UPDATE, "Ticket already Exists") Happy Hacking: Roger 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.