Calendar problem

Hello,

Just joined up and this is my first post. I have a calendar script with an annoying bug, I think I know what’s wrong but I’m not good enough with php to fix it. The problem is that sometimes people can join the event more than once and take up more spaces than they are entitled to. They should only be able to join the event once.
This calendar is for a diving club and we use it to arrange our dives.

[php]<?php
include (“inc/functions.inc”);
include (“inc/dbconnect.inc”);
$db = mysql_connect($server, $username, $password);
mysql_select_db($dbName,$db);
$images = mysql_query(“SELECT DISTINCT ID FROM images ORDER BY RAND() LIMIT 25”, $db);
if (!$images) {
die('Invalid query: ’ . mysql_error());
}
$dbarraysize = mysql_num_rows($images)-1;
for ($g=0;$g <=$dbarraysize;$g++){
$dbarray[$g] = mysql_result($images,$g,‘ID’);
}

$result = mysql_query("SELECT * FROM calendar WHERE ID LIKE ".$_POST[‘event’], $db);
if (!$result) {
die('Invalid query: ’ . mysql_error());
}

//The problem is here I think
if (mysql_result($result,0,‘Participants’) == ‘’) {
$participants = $_POST[‘user’];
}else {
$participants = mysql_result($result,0,‘Participants’).",".$_POST[‘user’];
}

$dbupdate = mysql_query("UPDATE calendar SET participants = ‘$participants’ WHERE ID LIKE ".$_POST[‘event’], $db);
if (!$dbupdate) {
die('Invalid query: ’ . mysql_error());
}
if (mysql_result($result,0,‘Notify’) == 1){
$owner = mysql_result($result,0,‘Owner’);
$ownersearch = mysql_query("SELECT Mail FROM users WHERE ID LIKE ".$owner, $db);
if (!$ownersearch) {
die('Invalid query: ’ . mysql_error());
}
$usersearch = mysql_query("SELECT * FROM users WHERE ID LIKE “.$_POST[‘user’], $db);
if (!$usersearch) {
die('Invalid query: ’ . mysql_error());
}
$to = mysql_result($ownersearch,0,‘Mail’);
$username = mysql_result($usersearch,0,‘Name’);
$msg = $username.” has joined the following event: “.mysql_result($result,0,‘Title’);
$subject = “A member has joined your event”;
$from = "[email protected]”;
mail($to, $subject,$msg,'From: '.$from);
}
Echo “”;
Endtable();
?>[/php]

Can anyone help me out with this? Thanks. I plan to modify the calendar at a later date and use google calendar api to use google as the back end.

I can tell by reading the code you could certainly use better table logic. Using LIKE should be avoided unless absolutely necessary.

Ultimately I think you will need to have a sort of unique link table like

UNIQUE calendar_id
UNIQUE user_id

This would prevent the table from holding any duplicate user_id for a calendar_id

Also, when a member attempts to reserve a date, you should first check to see if they are already
on the list for that dive. If they are, then, you should send them a notice stating so and never actually
post the reservation. If you set up your checking correctly, this will never happen in the first place.

Just my opinion…

Sponsor our Newsletter | Privacy Policy | Terms of Service