PHP Help!

Soldato
Joined
21 Jul 2004
Posts
6,360
Location
Harrow, UK
I modified a RSVP script a few months back, without much PHP knowledge, and for the first time today, we have tried to list two events at the same time, and it is coming up with the following error:

Code:
Fatal error: Cannot redeclare dateconvert() (previously declared in g:\socs\su200\events\view-events.php:105) in g:\socs\su200\events\view-events.php on line 105

Now I think this error is coming up because I have added a function to convert from American date format to British format, and it is trying to declare the function again when it goes through the script to display the second event. Here is the file - any help would be great:

PHP:
<?php
require_once('./conf/conf.inc.php');
require_once('./functions/dbquote.php');
require_once('./functions/httpredir.php');
$page_title = "List of Events";
$style_sheet = "./styles/style.css";
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="generator" content="RSVP 2.0" />
<meta keywords="rsvp script, reservation script">
<link rel="stylesheet" href="<?php echo $style_sheet; ?>" type="text/css">
<title><?php echo $page_title; ?></title>
</head>

<body>

<div id="main">

<?php
  
  // Number of results to show on a page.	
  define('RESULTS_PER_PAGE', 10);

  // ensure that inadvertent changes made to the url get parameters are fixed	
  if(!isset($_GET['pg_num'])) { 
    $pg_number = 1;
  } else {
	if($_GET['pg_num'] < 2) {
           $pg_number = 1; 
        } else { 
	  $pg_number = $_GET['pg_num'];
        }
  }	
  $link = @mysql_connect(SQL_HOST, SQL_USER, SQL_PASS) or die("Could not connect to the database: " . mysql_error());
  @mysql_select_db(SQL_DB, $link) or die(mysql_error());
  // count the number of events in the database for paging results 
  $sql_for_num_results = "SELECT COUNT(*) ";
  $sql_for_num_results .= "FROM `events` ";
  
  $result = @mysql_query($sql_for_num_results, $link);
  $row = @mysql_fetch_array($result, MYSQL_NUM);  
  $num_results = $row[0];
  // unset variables not needed
  unset($result);
  unset($row);
  unset($sql_for_num_results);
  
  // lower limit for the paging query
  $floor = RESULTS_PER_PAGE * ($pg_number - 1);
  
  $num_pages = ceil($num_results / RESULTS_PER_PAGE);	
  $sql_for_event_listing = "SELECT event_id, event_name, event_date, event_location, event_time, max_participants, event_status, num_reserved ";
  $sql_for_event_listing .= "FROM `events` LIMIT " . $floor . ", " . RESULTS_PER_PAGE;
  $event_result = @mysql_query($sql_for_event_listing, $link);
  ?>
<br />
<?php
if($num_pages > 1) {
?>
<table style="margin-left: 12px; padding-right: 2px"><tr>
<?php
for($i=1; $i<=$num_pages; $i++) {
?>
<td><a style="color: #fff" href="<?php echo $_SERVER['PHP_SELF'] . '?pg_num=' . $i; ?>"><?php echo $i . ' ';?></a></td>
<?php
}
}
?>
</tr></table>
<br />

  <form action="event-registration.php" method="GET">
  <div align="center">
  <table class="tablestyle2">
  <tr><td bgcolor="#dfe5ef" width="3%" align="center">Select</td>
  <td bgcolor="#dfe5ef" width="33%" align="center">Event Title</td>
  <td bgcolor="#edf2f5" width="10%" align="center">Date</td>
  <td bgcolor="#dfe5ef" width="8%" align="center">Location</td>
  <td bgcolor="#edf2f5" width="5%" align="center">Time</td>
  <td bgcolor="#dfe5ef" width="8%" align="center">Max. Participants</td>
  <td bgcolor="#edf2f5" width="8%" align="center">Booking Status</td>
  <td bgcolor="#dfe5ef" width="5%" align="center">Reserved</td>
  <td bgcolor="#71A6C1" width="8%" align="center"><span style="color: #fff">View Details</span></td>
  </tr>

  <?php
  while($row = @mysql_fetch_array($event_result, MYSQL_NUM)) {
  ?>
<tr><td bgcolor="#dfe5ef" width="3%" align="center">
<?php
if($row[5] > $row[7]) {
?>
<input type='radio' name='select_events' value="<?php echo $row[0]; ?>">
<?php } else {
echo "<span style=\"color: red\">X</span>";
} ?>
  </td><td bgcolor="#edf2f5" width="5%" align="center">
  <?php

function dateconvert($date) {
            list($year, $month, $day) = split('[-.]', $date); 
            $date = "$day-$month-$year"; 
            return $date;
} 
?>
<?php
$date = $row[2]; //your mysql date
$row[2] = dateconvert($date);

echo $row[1]. '</td><td bgcolor="#edf2f5" width="10%" align="center">' .  $row[2]. '</td><td bgcolor="#dfe5ef" width="14%" align="center">' .  $row[3]. '</td><td bgcolor="#edf2f5" width="6%" align="center">' .  $row[4]. '</td><td bgcolor="#dfe5ef" width="8%" align="center">' . $row[5] . '</td><td bgcolor="#edf2f5" width=8%" align="center">';
if($row[5] > $row[7]) {
echo $row[6];
} else {
echo '<span style="color: red">' . $row[6] . '</span>';
}
echo '</td><td bgcolor="#dfe5ef" align="center" width="5%">' . $row[7] .'</td>';
?>
<td bgcolor="#edf2f5" width="8%" align="center"><a href="view-event-details.php?event_id=<?php echo $row[0]; ?>">View</a></td>
</tr>
<?php  
}
?>

</table>
<br />
table>
<tr>
<td>
<input class='liteoption' type="submit" name="submit" value="Register" /></td>
</tr></table>

</form>
</div>
<?php
unset($row);
  unset($event_result);
  unset($sql_for_event_listing);  

  @mysql_close($link);
?>
<div align="center">
<span class="footer">Copyright &copy; 2005 <?php echo $admin['from_name']; ?> All rights reserved. <font color="FF0000"><a href="http://www.cescripts.com">Powered by RSVP 2.0</a></font></span>
</div>
</body></html>
 
MastermindUK said:
Code:
if(!function_exists('dateconvert'){
	function dateconvert($date) {
				list($year, $month, $day) = split('[-.]', $date); 
				$date = "$day-$month-$year"; 
				return $date;
	} 
}

I guess you could do the above.

Cheers :D

/Edit: MuvverRussia pointed out that it needs an extra ) in the first line ;)
 
Back
Top Bottom