Jump to content

[SOLVED] can't get my userchecking to work


contra10

Recommended Posts

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>');
}
}
?>

Link to comment
Share on other sites

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'];
}
...
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.