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
https://forums.phpfreaks.com/topic/142575-solved-cant-get-my-userchecking-to-work/
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>

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

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

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

Archived

This topic is now archived and is closed to further replies.

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