Click to See Complete Forum and Search --> : duplicate values...


*TeKKeD*
04-04-2005, 07:34 AM
i just got a major error! when i enter an event, say for april 4th, 2005, and i go to either april 4th, 2004 or april 4th, 2006, the same entry is there aswell.... how do i get ride of this???

this is for an events database...

solomon
04-04-2005, 08:46 AM
you'll need to be a lot more specific - can you show us your scripts / db structure etc...

*TeKKeD*
04-04-2005, 09:41 AM
index.php

<?
require_once("config.php");
$db_connection = mysql_connect ($DBHost, $DBUser, $DBPass) OR die (mysql_error());
$db_select = mysql_select_db ($DBName) or die (mysql_error());
$table_1 = "events";
$table_2 = "dept";

function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}

$time_start = getmicrotime();

if (!isset($_GET['year'])){
$_GET['year'] = date("Y");
}
if (!isset($_GET['month'])){
$_GET['month'] = date("n")+1;
}

$month = $_GET['month'] - 1;
$sql = "SELECT event_id, title, event_day, event_time FROM $table_1 WHERE event_month='$month' ORDER BY event_time";
$query_result = mysql_query($sql);
while ($info = mysql_fetch_array($query_result))
{
$day = $info['event_day'];
$event_id = $info['event_id'];
$events[$day][] = $info['event_id'];
$event_info[$event_id]['0'] = substr($info['title'], 0, 8);;
$event_info[$event_id]['1'] = $info['event_time'];
}

$todays_date = date("j");
$todays_month = date("n");

$days_in_month = date ("t", mktime(0,0,0,$_GET['month'],0,$_GET['year']));
$first_day_of_month = date ("w", mktime(0,0,0,$_GET['month']-1,1,$_GET['year']));
$first_day_of_month = $first_day_of_month + 1;
$count_boxes = 0;
$days_so_far = 0;

IF($_GET['month'] == 13){
$next_month = 2;
$next_year = $_GET['year'] + 1;
} ELSE {
$next_month = $_GET['month'] + 1;
$next_year = $_GET['year'];
}

IF($_GET['month'] == 2){
$prev_month = 13;
$prev_year = $_GET['year'] - 1;
} ELSE {
$prev_month = $_GET['month'] - 1;
$prev_year = $_GET['year'];
}



?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Events Calendar</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="cal.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
function window(page) {
OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=500,height=200");
}
function window2(page) {
OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=600,height=300");
}
//-->
</script>
</head>

<body>
<div align="center"><span class="currentdate"><font size="+2"><? echo date ("F Y", mktime(0,0,0,$_GET['month']-1,1,$_GET['year'])); ?></font></span><br>
<br>
</div>
<div align="center"><br>
<table width="700" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="right"><a href="<? echo "index.php?month=$prev_month&amp;year=$prev_year"; ?>">&lt;&lt;</a></div></td>
<td width="200"><div align="center">

<select name="month" class="addevent" id="month" onChange="MM_jumpMenu('parent',this,0)">
<?
for ($i = 1; $i <= 12; $i++) {
$link = $i+1;
IF($_GET['month'] == $link){
$selected = "selected";
} ELSE {
$selected = "";
}
echo "<option value=\"index.php?month=$link&amp;year=$_GET[year]\" $selected>" . date ("F", mktime(0,0,0,$i,1,$_GET['year'])) . "</option>\n";
}
?>
</select>
<select name="year" class="addevent" id="year" onChange="MM_jumpMenu('parent',this,0)">
<?
for ($i = 2000; $i <= 2010; $i++) {
IF($i == $_GET['year']){
$selected = "selected";
} ELSE {
$selected = "";
}
echo "<option value=\"index.php?month=$_GET[month]&amp;year=$i\" $selected>$i</option>\n";
}
?>
</select>
</div></td>
<td><div align="left"><a href="<? echo "index.php?month=$next_month&amp;year=$next_year"; ?>">&gt;&gt;</a></div></td>
</tr>
</table>
<br>
</div>
<table width="700" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#000000">
<tr>
<td><table width="100%" border="0" cellpadding="0" cellspacing="1">
<tr class="topdays">
<td><div align="center">Sunday</div></td>
<td><div align="center">Monday</div></td>
<td><div align="center">Tuesday</div></td>
<td><div align="center">Wednesday</div></td>
<td><div align="center">Thursday</div></td>
<td><div align="center">Friday</div></td>
<td><div align="center">Saturday</div></td>
</tr>
<tr valign="top" bgcolor="#FFFFFF">
<?
for ($i = 1; $i <= $first_day_of_month-1; $i++) {
$days_so_far = $days_so_far + 1;
$count_boxes = $count_boxes + 1;
echo "<td width=\"100\" height=\"100\" class=\"beforedayboxes\"></td>\n";
}
for ($i = 1; $i <= $days_in_month; $i++) {
$days_so_far = $days_so_far + 1;
$count_boxes = $count_boxes + 1;
IF($_GET['month'] == $todays_month+1){
IF($i == $todays_date){
$class = "highlighteddayboxes";
} ELSE {
$class = "dayboxes";
}
} ELSE {
IF($i == 1){
$class = "highlighteddayboxes";
} ELSE {
$class = "dayboxes";
}
}
echo "<td width=\"100\" height=\"100\" class=\"$class\">\n";
$link_month = $_GET['month'] - 1;
echo "<div align=\"right\"><span class=\"toprightnumber\">\n<a href=\"javascript:window2('event_add.php?day=$i&amp;month=$link_month&amp;year=$_GET[year]')\">$i</a>&nbsp;</span></div>\n";
IF(isset($events[$i])){
echo "<div align=\"left\"><span class=\"eventinbox\">\n";
while (list($key, $value) = each ($events[$i])) {
echo "&nbsp;<a href=\"javascript:window('event.php?id=$value')\">" . $event_info[$value]['1'] . " " . $event_info[$value]['0'] . "</a>\n<br>\n";
}
echo "</span></div>\n";
}
echo "</td>\n";
IF(($count_boxes == 7) AND ($days_so_far != (($first_day_of_month-1) + $days_in_month))){
$count_boxes = 0;
echo "</TR><TR valign=\"top\">\n";
}
}
$extra_boxes = 7 - $count_boxes;
for ($i = 1; $i <= $extra_boxes; $i++) {
echo "<td width=\"100\" height=\"100\" class=\"afterdayboxes\"></td>\n";
}
$time_end = getmicrotime();
$time = round($time_end - $time_start, 3);
?>
</tr>
</table></td>
</tr>
</table>
</body>
</html>

*TeKKeD*
04-04-2005, 09:43 AM
event_add.php:

<?
if(isset($_POST['submit'])){
require_once("config.php"); $db_connection = mysql_connect ($DBHost, $DBUser, $DBPass) OR die
(mysql_error());
$db_select = mysql_select_db ($DBName) or die (mysql_error());
$table_1 = "events";
$table_2 = "dept";

$sql = "INSERT INTO $table_1 (`event_day` , `event_month` , `event_year` , `event_time` , `title` , `description`) VALUES ('".$_POST['day']."', '".$_POST['month'] . "', '".$_POST['event_year'] . "', '" . $_POST['hour'] . ":" . $_POST['minute'] . "', '" . $_POST['title']."', '".$_POST['description']."')";//only close one.
echo 'DEBUG1: '.$sql.'<br />';
mysql_query($sql) or die(mysql_error());
$_POST['month']++;

$sql2 = "INSERT INTO $table_2 ('dept_name') VALUES '".$_POST['dept']."'";
echo 'DEBUG2: '.$sql.'<br />';
mysql_query($sql2);
$_POST['month']++;
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Calendar - Add Event</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language='javascript' type="text/javascript">
<!--
function redirect_to(where, closewin)
{
opener.location= 'index.php?' + where;

if (closewin == 1)
{
self.close();
}
}
//-->
</script>
</head>
<body onLoad="javascript:redirect_to('<? echo "month=$_POST[month]&year=$_POST[year]"; ?>',1);">
</body>
</html>
<?
} ELSE {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Calendar - Add Event</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="cal.css" rel="stylesheet" type="text/css">
</head>
<body>
<form name="form1" method="post" action="">
<table width="480" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="200" height="40" valign="top"><span class="addevent">Event Date</span><br>
<span class="addeventextrainfo">(MM/DD/YY)</span></td>
<td height="40" valign="top"> <select name="month" id="month">
<option value="1" <? IF($_GET['month'] == "1"){ echo "selected"; } ?>>01</option>
<option value="2" <? IF($_GET['month'] == "2"){ echo "selected"; } ?>>02</option>
<option value="3" <? IF($_GET['month'] == "3"){ echo "selected"; } ?>>03</option>
<option value="4" <? IF($_GET['month'] == "4"){ echo "selected"; } ?>>04</option>
<option value="5" <? IF($_GET['month'] == "5"){ echo "selected"; } ?>>05</option>
<option value="6" <? IF($_GET['month'] == "6"){ echo "selected"; } ?>>06</option>
<option value="7" <? IF($_GET['month'] == "7"){ echo "selected"; } ?>>07</option>
<option value="8" <? IF($_GET['month'] == "8"){ echo "selected"; } ?>>08</option>
<option value="9" <? IF($_GET['month'] == "9"){ echo "selected"; } ?>>09</option>
<option value="10" <? IF($_GET['month'] == "10"){ echo "selected"; } ?>>10</option>
<option value="11" <? IF($_GET['month'] == "11"){ echo "selected"; } ?>>11</option>
<option value="12" <? IF($_GET['month'] == "12"){ echo "selected"; } ?>>12</option>
</select> <select name="day" id="day">
<option value="1" <? IF($_GET['day'] == "1"){ echo "selected"; } ?>>01</option>
<option value="2" <? IF($_GET['day'] == "2"){ echo "selected"; } ?>>02</option>
<option value="3" <? IF($_GET['day'] == "3"){ echo "selected"; } ?>>03</option>
<option value="4" <? IF($_GET['day'] == "4"){ echo "selected"; } ?>>04</option>
<option value="5" <? IF($_GET['day'] == "5"){ echo "selected"; } ?>>05</option>
<option value="6" <? IF($_GET['day'] == "6"){ echo "selected"; } ?>>06</option>
<option value="7" <? IF($_GET['day'] == "7"){ echo "selected"; } ?>>07</option>
<option value="8" <? IF($_GET['day'] == "8"){ echo "selected"; } ?>>08</option>
<option value="9" <? IF($_GET['day'] == "9"){ echo "selected"; } ?>>09</option>
<option value="10" <? IF($_GET['day'] == "10"){ echo "selected"; } ?>>10</option>
<option value="11" <? IF($_GET['day'] == "11"){ echo "selected"; } ?>>11</option>
<option value="12" <? IF($_GET['day'] == "12"){ echo "selected"; } ?>>12</option>
<option value="13" <? IF($_GET['day'] == "13"){ echo "selected"; } ?>>13</option>
<option value="14" <? IF($_GET['day'] == "14"){ echo "selected"; } ?>>14</option>
<option value="15" <? IF($_GET['day'] == "15"){ echo "selected"; } ?>>15</option>
<option value="16" <? IF($_GET['day'] == "16"){ echo "selected"; } ?>>16</option>
<option value="17" <? IF($_GET['day'] == "17"){ echo "selected"; } ?>>17</option>
<option value="18" <? IF($_GET['day'] == "18"){ echo "selected"; } ?>>18</option>
<option value="19" <? IF($_GET['day'] == "19"){ echo "selected"; } ?>>19</option>
<option value="20" <? IF($_GET['day'] == "20"){ echo "selected"; } ?>>20</option>
<option value="21" <? IF($_GET['day'] == "21"){ echo "selected"; } ?>>21</option>
<option value="22" <? IF($_GET['day'] == "22"){ echo "selected"; } ?>>22</option>
<option value="23" <? IF($_GET['day'] == "23"){ echo "selected"; } ?>>23</option>
<option value="24" <? IF($_GET['day'] == "24"){ echo "selected"; } ?>>24</option>
<option value="25" <? IF($_GET['day'] == "25"){ echo "selected"; } ?>>25</option>
<option value="26" <? IF($_GET['day'] == "26"){ echo "selected"; } ?>>26</option>
<option value="27" <? IF($_GET['day'] == "27"){ echo "selected"; } ?>>27</option>
<option value="28" <? IF($_GET['day'] == "28"){ echo "selected"; } ?>>28</option>
<option value="29" <? IF($_GET['day'] == "29"){ echo "selected"; } ?>>29</option>
<option value="30" <? IF($_GET['day'] == "30"){ echo "selected"; } ?>>30</option>
<option value="31" <? IF($_GET['day'] == "31"){ echo "selected"; } ?>>31</option>
</select> <select name="year" id="year">
<option value="2003" <? IF($_GET['year'] == "2003"){ echo "selected"; } ?>>2003</option>
<option value="2004" <? IF($_GET['year'] == "2004"){ echo "selected"; } ?>>2004</option>
<option value="2005" <? IF($_GET['year'] == "2005"){ echo "selected"; } ?>>2005</option>
<option value="2006" <? IF($_GET['year'] == "2006"){ echo "selected"; } ?>>2006</option>
<option value="2007" <? IF($_GET['year'] == "2007"){ echo "selected"; } ?>>2007</option>
</select> </td>
</tr>
<tr>
<td width="200" height="40" valign="top"><span class="addevent">Event Time</span><br>
<span class="addeventextrainfo">(24hr Format)</span></td>
<td height="40" valign="top"> <input name="hour" type="text" id="hour" value="20" size="2" maxlength="2">
:
<input name="minute" type="text" id="minute" value="00" size="2" maxlength="2">
</td>
</tr>
<tr>
<td width="200" height="40" valign="top"><span class="addevent">Event Title</span></td>
<td height="40" valign="top"> <input name="title" type="text" id="title" size="20">
</td>
</tr>
<tr>
<td height="40" valign="top"><font size="2" face="Verdana, Arial, Helvetica, sans-serif" class="addevent">Type of event:</font></td>
<td height="40" valign="top"><input name="type_event" type="text" id="type_event"></td>
</tr>
<tr>
<td height="40" valign="top" class="addevent"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Department:</font></td>
<td height="40" valign="top"><input name="dept" type="text" id="dept"></td>
</tr>
<tr>
<td height="40" valign="top" class="addevent"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Section:</font></td>
<td height="40" valign="top"><input name="section" type="text" id="section"></td>
</tr>
<tr>
<td width="200" height="40" valign="top"><span class="addevent">Event Description</span></td>
<td height="40" valign="top"> <textarea name="description" cols="18" rows="5" id="description"></textarea>
</td>
</tr>
<tr>
<td width="200">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="submit" type="submit" id="submit" value="add event"></td>
</tr>
</table>
</form>
</body>
</html>
<? } ?>

*TeKKeD*
04-04-2005, 09:48 AM
Those above are the two main files, index has the calendar script that genereates the values as given to by event_add.php and echo's it title in the calendar.

and of course event_add.php adds the values received by the user in the provided text fields, into that database and are passed to index.php for proper viewing using a calendar.

structure for events_db:

CREATE TABLE `events` (
`event_id` int(11) NOT NULL auto_increment,
`dept_id` int(11) NOT NULL default '0',
`section_id` int(11) NOT NULL default '0',
`oo_id` int(11) NOT NULL default '0',
`location_id` int(11) NOT NULL default '0',
`action_id` int(11) NOT NULL default '0',
`event_day` int(2) NOT NULL default '0',
`event_month` int(2) NOT NULL default '0',
`event_year` int(4) NOT NULL default '0',
`event_time` varchar(5) NOT NULL default '',
`title` varchar(100) NOT NULL default '0',
`type_id` int(11) NOT NULL default '0',
`user_id` int(1) NOT NULL default '0',
`project_manager` int(1) NOT NULL default '0',
`other_contact` int(1) NOT NULL default '0',
`description` text NOT NULL,
PRIMARY KEY (`event_id`),
KEY `dept_id` (`dept_id`,`section_id`,`oo_id`,`location_id`,`action_id`,`event_day`,`event_month`,`event_year`,`ti tle`,`type_id`,`user_id`,`project_manager`,`other_contact`)
) TYPE=MyISAM

Hope this helps :)

*TeKKeD*
04-05-2005, 02:16 AM
Hello????