contra10 Posted January 27, 2009 Share Posted January 27, 2009 hi i want a button to not display if the useralready exists for an event my coding is <?php if(is_numeric($_GET['ev'])){ $id = $_GET['ev']; } if (isset($_POST['submit'])){ // checks if the username is in use for event $check = mysql_query("SELECT * FROM `events_subscribers` WHERE `eventid` = '$id' AND `username`='$username'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the username for event exists it gives an error if ($check2 > 1) { die('<FONT FACE=ariel size=6><b>You are attending this event</b></FONT>'); } ?> followed by an else statement for the button the button keeps showing even if a person has already joined...i checked my query all elements are in it and all names are correct Quote Link to comment Share on other sites More sharing options...
.josh Posted January 27, 2009 Share Posted January 27, 2009 Unless you are doing it somewhere else or have register globals on, you aren't assigning anything to $username. Also, you'll want to check if $check2 > 0, not > 1. Quote Link to comment Share on other sites More sharing options...
contra10 Posted January 27, 2009 Author Share Posted January 27, 2009 ok i see where i went wrong...but how should i fix this...i noticed the form is outsidde of the php tags...(duh to mysself) <?php if(is_numeric($_GET['ev'])){ $id = $_GET['ev']; } if (isset($_POST['submit'])){ // checks if the username is in use for event $check = mysql_query("SELECT * FROM `events_subscribers` WHERE `eventid` = '$id' AND `username`='$username'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the username for event exists it gives an error if ($check2 > 0) { die('<FONT FACE=ariel size=6><b>You are attending this event</b></FONT>'); } else{ $query= "SELECT * FROM `events` WHERE `eid` = '$id'"; $result = mysql_query($query) or die(mysql_error());; $event = mysql_fetch_assoc($result); $eventname = "{$event['evname']}"; $eventid = "{$event['eid']}"; $query2= "SELECT `id` FROM `users` WHERE `username` = '$username'"; $result2 = mysql_query($query2) or die(mysql_error());; $usera = mysql_fetch_assoc($result2); $userid = "{$usera['id']}"; $insert = "INSERT INTO `events_subscribers` (userid, username, eventid, eventname) VALUES ('$userid', '$username', '$eventid', '$eventname')"; $add_subscription = mysql_query($insert) or die(mysql_error()); // Create the URL string $url = "http://localhost/events/eventview.php?ev=$id"; // Finall Echo the meta tag echo('<meta HTTP-EQUIV="REFRESH" content="0; url='.$url.'">'); } } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type='submit' name='submit' value='Attend Event'></td> <input type='hidden' name='ev' value='<?php echo $_GET['ev']; ?>'> </form> Quote Link to comment Share on other sites More sharing options...
.josh Posted January 27, 2009 Share Posted January 27, 2009 I still don't see any place where you are assigning something to $username. Is the user supposed to be entering their username into the form? Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 27, 2009 Share Posted January 27, 2009 a bit neater(( might work? <?php if (isset($_POST['submit'])){ $check = mysql_query("SELECT * FROM `events_subscribers` WHERE `eventid` = IsNumeric(mysql_real_escape_string('{$_GET['ev']}') AND `username`='$username'") or die(mysql_error()); if(mysql_num_rows($check)>0){ die('<FONT FACE=ariel size=6><b>You are attending this event</b></FONT>'); } } ?> Quote Link to comment Share on other sites More sharing options...
contra10 Posted January 27, 2009 Author Share Posted January 27, 2009 no the username is recieved from cookie file, which is echoed in header.php ill input itto the code though to make it easier <?php if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; } if(is_numeric($_GET['ev'])){ $id = $_GET['ev']; } ... ?> Quote Link to comment Share on other sites More sharing options...
.josh Posted January 27, 2009 Share Posted January 27, 2009 okay so echo out all of your vars and see if they all have what they should be having. Quote Link to comment Share on other sites More sharing options...
contra10 Posted January 27, 2009 Author Share Posted January 27, 2009 another dumb mistake...i should have echoed the check before i ran the submit...like this <?php if(is_numeric($_GET['ev'])){ $id = $_GET['ev']; } // checks if the username is in use for event $check = mysql_query("SELECT * FROM `events_subscribers` WHERE `eventid` = '$id' AND `username`='$username'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the username for event exists it gives an error if ($check2 > 0) { die('<FONT FACE=ariel size=6><b>You are attending this event</b></FONT>'); } if (isset($_POST['submit'])){ ?> thnks 4 the help 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.