Jump to content
MakeWebGames

Filtering information


bineye

Recommended Posts

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;
		}
		}
Link to comment
Share on other sites

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 by sniko
Link to comment
Share on other sites

  • 4 weeks later...

@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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...