PHP - Array_map Prob.
please check the following code. It gave me this error Warning:
Code: [Select] array_map(): The first argument, 'self::prepSessions', should be either NULL or a valid callback public function resetSess(){ if($this->isLoggedIn){ session_regenerate_id(); $this->sessions = array( 'userId' => $_SESSION['userId'], 'username' => $_SESSION['username'], 'password' => $_SESSION['password'], 'uemail' => $_SESSION['uemail'], 'userLevel' => $_SESSION['userLevel'], 'userGroup' => $_SESSION['userGroup'], 'referrer' => $_SESSION['referrer'] ); $this->userdata = array_map("self::prepSessions", $this->sessions); }else{ return false; } } public function prepSessions($sessions){ if($this->isLoggedIn){ return $sessions; } } Similar TutorialsHowdy, this one is killing me! Hope some of the genius here will rub off on me. Very simple example of what is happening: Base.php Code: [Select] class Base_Model //class autoloaded { protected function scrub($value) { return trim(htmlspecialchars($value, ENT_QUOTES, "UTF-8")); } } Foo.php Code: [Select] class Foo_Model extends Base_Model { if($_POST) { $_POST = array_map('parent::scrub', $_POST); } } This works perfectly on the workstation (MAMP) server, but generates a warning ( Warning: array_map() [function.array-map]: The first argument, 'parent::scrub', should be either NULL or a valid callback in... ) when uploaded to the production server. Both are running the exact same version of php. Any ideas would be appreciated on getting rid of the error, besides turning off warnings ( haha ). William This is just for fun/exploring. The normal way of iterating over a array is using a for() loop. The functional way is to use array_map . I am trying to write/emulate the array_map function in a functional way. Emulating the array_map using a for loop is easy: function array_map_me_normal($callback,$arr){ $returnArr = []; for ($i =0 ; $i < count($arr);$i++){ $returnArr[] = $callback($arr); } return $returnArr; } But emulating array_map using a functional approach seems to be tricky. Not sure if its even possible. I think it should be possible.. function array_map_me_functional($callback,$arr){ if (empty($arr)){ return false; } return [$callback(array_pop($arr)), $callback($arr)]; } The above is incorrect ofcourse. Returns increasing nested array. But I couldn't do better. Is there a way ? or will an array_map function always be using for loop under its hood ? Thanks this is my code Code: [Select] <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>"> <p> <label for="onoma">Όνομα<br /> </label> <input name="onoma" type="text" id="onoma" size="40" /> </p> <p> <label for="epitheto">Επίθετο</label> <br /> <input name="epitheto" type="text" id="epitheto" size="40" /> </p> <p> <label for="Email">Email<br /> </label> <input name="Email" type="text" id="Email" size="40" /> </p> <p> <label for="Thlefono">Τηλέφωνο</label> <br /> <input name="Thlefono" type="text" id="Thlefono" size="40" /> </p> <p>Διεύθυνση<br /> <label for="die"></label> <input name="die" type="text" id="die" size="40" /> </p> <p>Ημερομηνία που επιθειμείτε να γίνει η Κρατηση<br /> <input name="hmerominia" type="text" id="hmerominia" size="40" /> </p> <p>Ωρα στην παραπάνω ημερομηνία που επιθειμείτε <input name="wra" type="text" id="wra" size="40" /> </p> <p> <label for="Minima">Άλλο Μύνημα</label> <br /> <textarea name="Minima" id="Minima" cols="50" rows="10"></textarea> </p> <p> <input type="submit" name="submit" id="submit" value="Submit" /> </p> <input type="hidden" name="MM_insert" value="form1" /> <br/> </form> <?php if (is_null($_POST)) { echo "<h4>Η επικύρωση της κράτησης θα γίνει απο εμάς τηλεφωνικά<br /> στο τηλέφωνο που εισάγατε. </h4> <h4>Η διαδικασία κράτησης διαρκεί 1 ημέρα</h4>"; } else{ echo "eyxaristoume kyrie"; echo $_REQUEST["onoma"]; echo " "; echo $_REQUEST["epitheto"]; echo "poy kanante kratisi sto katastima maestros" ;} ?> and this is the form action Code: [Select] <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO kratisi (onoma, epi8eto, thlefono, dieuthinsi, email, hmerominia, wra, minima) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['onoma'], "text"), GetSQLValueString($_POST['epitheto'], "text"), GetSQLValueString($_POST['Thlefono'], "text"), GetSQLValueString($_POST['die'], "text"), GetSQLValueString($_POST['Email'], "text"), GetSQLValueString($_POST['hmerominia'], "text"), GetSQLValueString($_POST['wra'], "text"), GetSQLValueString($_POST['Minima'], "text")); mysql_select_db($database_maestr, $maestr); $Result1 = mysql_query($insertSQL, $maestr) or die(mysql_error()); $insertGoTo = "contact.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?>i want to make the form work like this when someone gets to that for first time to say something at the bottom and when he pushes the submit button it will say thank you i tried to do it with post if post is empty to say something and when it isnt empty to say thank you but it doesnt work where is my fault if someone can help me.. hello guys, am getting prob in array_splice( ) . if i try to insert an element into an associative array, that element is converted into indexed array. <?php $capitals = array('USA' => 'Washington', 'Great Britain' => 'London', 'New Zealand' => 'Wellington', 'Australia' => 'Canberra', 'Italy' => 'Rome'); $france = array('France' => 'Paris'); array_splice($capitals, 1, 0, $france); print_r($capitals); ?> am getting output as Array ( [USA] => Washington => Paris [Great Britain] => London [New Zealand] => Wellington [Australia] => Canberra [Italy] => Rome ). pls guys help me on this...why key index is not printing as france instead of 0.. Hey guys, longtime reader first time poster. i seem to be having a pagination problem and i think that some fresh eyes are in order im sure its staring in front of me.......just cant see it Code: [Select] <?php global $main; $main->query('upgraded', "SELECT `auctions`.*, `categories`.* FROM `auctions` LEFT JOIN `categories` ON `category_id` = `auction_category_id` WHERE `auction_upgrade_color` = '1' ORDER BY `auction_id` DESC LIMIT {$main->upgraded_auctions_max}"); if (!$main->auth['logged_in']) { header('Location: ' . SITE_BASE . '/login/'); } ?> <div class="left"> <? include('php/inc.featured-listings.php'); ?> </div> <div class="right"> <?php #pagination $sql = "SELECT `auction_id` FROM `auctions` WHERE `auction_user_id` = {$main->auth[user_id]}"; $q = mysql_query($sql); $page_count = ceil(mysql_num_rows($q) / $main->auctions_per_page); $current_page = (int) $_GET['current_page'] > 0 && (int) $_GET['current_page'] <= $page_count ? $_GET['current_page'] : 1; $offset = ($current_page - 1) * $main->auctions_per_page; $order = in_array($_GET['order'], array('auction_id', 'auction_views', 'auction_title', 'category_name')) ? $_GET['order'] : 'auction_id'; #listings if (!$_GET['auction_id']): $title = 'My Current Listings'; #query for newest listings $sql = "SELECT `auctions`.*, `categories`.*, `users`.* FROM `auctions` LEFT JOIN `categories` ON `category_id` = `auction_category_id` LEFT JOIN `users` ON `user_id` = `auction_user_id` WHERE `auction_user_id` = {$main->auth[user_id]} GROUP BY `$order` ORDER BY `$order` DESC LIMIT $offset, {$main->auctions_per_page}"; $q = mysql_query($sql); ?> <table cellpadding="0" cellspacing="0" class="listings" style="width: 703px;"> <tr class="header"> <td colspan="5"><h2><?php echo $title; ?></h2></td> </tr> <tr class="title"> <td width="50%" class="lborder">Listing Title</td> <td width="15%">Created In</td> <td width="15%">Created By</td> <td width="15%">Listed On</td> <td width="5%">Views</td> </tr> <?php while ($r = mysql_fetch_assoc($q)): ?> <tr class="listing<?php echo $r['auction_upgrade_color'] == '1' ? ' orange' : ''; ?>"> <td class="listing-title"><a href="/auction/<?php echo $r['auction_id']; ?>-<?php echo niceurls($r['auction_title']); ?>.html"><?php echo $r['auction_title']; ?></a></td> <td><a href="/category/<?php echo $r['category_url']; ?>/"><?php echo $r['category_name']; ?></a></td> <td><a href="/user/<?php echo $r['user_id']; ?>/"><?php echo $r['user_name']; ?></a></td> <td><?php echo howlongago($r['auction_time_listed']); ?></td> <td><?php echo number_format($r['auction_views']); ?></td> </tr> <?php endwhile; ?> </table> <div class="pagination"> <?php for ($i = 1; $i <= $page_count; $i++): ?> <a href="./?current_page=<?php echo $i; ?>"<?php echo $i == $current_page ? ' class="current"' : ''; ?>><?php echo $i; ?></a> <?php endfor; ?> </div> <?php endif; ?> </div> thanks in advance and yes i can laugh at myself Code: [Select] $query = 'select * from ob_listings where categoryid=' . $_POST["category"] . ' and subject like '%$term%' or description like '%$term%''; i want the query to select all from the table ob_listings where categoryid=$_post["category"] AND then from the items that fit that category subject like '%$term%' or description like '%$term%'' not that familiar with sql statements Ok so my problem is i need to change the page link. Now if i click on the link (marked with red) it will link to the company website. So, instead of going to the website. I want to change it to link to another page which i created named (oscar.php on my index.php). But without removing the company logo on it. This is my 1st time encounter this type of case since im very new. this is the index Code: [Select] <?session_start();?> <? include ('config.php'); include ('config_email.php'); include ('config_key.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>asia programs</title> <link rel="stylesheet" href="style.css" type="text/css" /> <script type="text/javascript" src="jquery/jquery.js"></script> <script type="text/javascript" src="jquery/thickbox/thickbox.js"></script> <link rel="stylesheet" href="jquery/thickbox/thickbox.css" type="text/css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> <link rel="stylesheet" href="jquery/jquery.treeview.css" /> <script src="jquery/lib/jquery.cookie.js" type="text/javascript"></script> <script src="jquery/jquery.treeview.js" type="text/javascript"></script> <link rel="stylesheet" href="css/globalslide.css"> <style type="text/css"> #footer2 { position:absolute; bottom:0; width:100%; height:140px; background: #000; opacity:0.9; filter:alpha(opacity=92); } /* for moz/opera and others*/ html>body #footer2{position:fixed} #footer2-inner{ height: 69px; background-color: black; } /* margin-bottom ensures last content is not obscured by footer */ #content { margin-bottom: 69px; }</style> </head> <body> <? if(isset($_GET[view])) { $view = $_GET[view]; } if(isset($_GET[content])) { $content = $_GET[content]; } if(isset($_GET[ttid])) { $ttid = $_GET[ttid]; } if(isset($_GET[mod])) { $mod = $_GET[mod]; } if(isset($_GET[note])) { $note = $_GET[note]; } if ($ttid <> ''){ if ($content == 'tips') { include (VIEWPAGE.'view_event_tooltip.php'); } if ($content == 'tesm') { include (VIEWPAGE.'view_event_testimonial.php'); } if ($content == 'psevent') { include (VIEWPAGE.'view_event_ps.php'); } if ($content == 'oscar') { include (VIEWPAGE.'view_event_description.php'); } if ($content == 'prospectus') { include (VIEWPAGE.'view_event_prospectus.php'); } if ($content == 'speaker') { include (VIEWPAGE.'view_event_speakerlist.php'); } } elseif ($ttid == ''){ ?> <div id="wrapper"> <? include ("header/header.php"); ?> <div id="main-content"> <? if ($content== ''){ if ($view == ''){ include (VIEWPAGE.'home.php'); include ("counter.php"); } if ($view == 'home'){ include (VIEWPAGE.'home.php'); } if ($view == 'about'){ include (VIEWPAGE.'view_aboutus.php'); } if ($view == 'sponsorship'){ include (VIEWPAGE.'view_sponsorship.php'); } if ($view == 'gallery'){ include (VIEWPAGE.'view_gallery.php'); } if ($view == 'subgallery'){ include (VIEWPAGE.'view_subgallery.php'); } if ($view == 'news'){ include (VIEWPAGE.'view_news.php'); } if ($view == 'subnews'){ include (VIEWPAGE.'view_subnews.php'); } if ($view == 'contact'){ include (VIEWPAGE.'view_contactus.php'); } if ($view == 'enquirysubmit'){ include (VIEWPAGE.'view_enquiry_thankyou.php'); } if ($view == 'career'){ include (VIEWPAGE.'view_career.php'); } if ($view == 'event'){ include (VIEWPAGE.'view_event_search.php'); } if ($view== 'spl'){ include (VIEWPAGE.'view_event_speakernote_list.php'); } } if ($view == 'home'){ if ($content== 'list'){ include (VIEWPAGE.'home.php'); } } if ($view == 'event'){ if ($content== 'list'){ include (VIEWPAGE.'view_event_searchlist.php'); } } if ($view == 'registration') { include (VIEWPAGE.'view_event_registration.php'); } if ($view == 'regmsgsuccess') { include (VIEWPAGE.'view_event_registration_msgsuccess.php'); } if ($view == 'regmsgerror') { include (VIEWPAGE.'view_event_registration_msgerror.php'); } if ($view == 'prospectus') { include (VIEWPAGE.'view_event_prospectus.php'); } if ($view == 'msgsuccess') { include (VIEWPAGE.'view_event_prospectus_msgsuccess.php'); } if ($view == 'msgerror') { include (VIEWPAGE.'view_event_prospectus_msgerror.php'); } if ($view == 'sn') { include (VIEWPAGE.'view_event_speakernote.php'); } if ($view == 'confirmation') { if ($mod == 'reg') { include (VIEWPAGE.'view_event_registration_insert.php'); } if ($mod == 'pro') { include (VIEWPAGE.'view_event_prospectus_insert.php'); } if ($mod == 'note') { include (VIEWPAGE.'view_event_speakernote_insert.php'); } if ($mod == 'ec') { include (VIEWPAGE.'view_event_speakernote_check.php'); } if ($mod == 'ecspreg') { include (VIEWPAGE.'view_event_speakernote_ecsuccess.php'); } } ?> </div> <? include ("footer/footer.php"); ?> </div> <? if (($view == 'home')|| ($view == '')){ ?> <? } } ?> </body></html> ok so this is the code for the page that i attached a photo of it Code: [Select] <? if(isset($_GET[ttid])) { $ttid = $_GET[ttid]; } $connection=mysql_connect("$server", "$username", "$password") or die("Could not establish connection"); mysql_select_db($database_name, $connection) or die ("Could not select database"); $query = "select master_event.* , (DATE_FORMAT(event_datefrom, '%d %M %Y')) as datefrom, (DATE_FORMAT(event_dateto, '%d %M %Y')) as dateto, ucase(event_name) as eventname from master_event where master_event.event_id = '$ttid '"; $result=mysql_query($query); while($row = mysql_fetch_array($result)){ $eventname = $row['eventname']; $eventdesc = $row['event_desc']; $companydescription = $row['company_description']; $eventvenue = $row['event_venue']; $eventfee = $row['event_fee']; $datefrom = $row['datefrom']; $dateto = $row['dateto']; echo "<font color='#000000' face='arial' ><b> $eventname </b> </font> <br>"; echo "<font color='#000000' face='arial' ><i>Date</i> : $datefrom - $dateto <br>"; echo "<i>Venue</i> : $eventvenue <br>"; $querypstype = "SELECT DISTINCT master_pstype.pstype_id, pstype_desc FROM master_pstype INNER JOIN master_psevent ON master_psevent.pstype_id= master_pstype.pstype_id where master_psevent.event_id = '$ttid' ORDER BY pstype_id"; $resultpstype=mysql_query($querypstype); while($rowpstype = mysql_fetch_array($resultpstype)){ $pstypeid = $rowpstype['pstype_id']; $pstypedesc = $rowpstype['pstype_desc']; echo "<br><font color='#8B3A3A' size='1' face='georgia' ><b><i>$pstypedesc</i></b></font> <br>"; $queryps = "SELECT master_psevent.*, pstype_desc, company_name, company_link, company_description, logo_filename FROM master_psevent LEFT JOIN master_pstype ON master_psevent.pstype_id = master_pstype.pstype_id LEFT JOIN master_ps ON master_ps.ps_id = master_psevent.ps_id WHERE master_psevent.event_id = '$ttid' and master_pstype.pstype_id= '$pstypeid' ORDER BY pstype_desc,company_name "; $resultps=mysql_query($queryps); while($rowps = mysql_fetch_array($resultps)){ $companyname = $rowps['company_name']; $companylinkori = $rowps['company_link']; $companydescription = $rowps['company_description']; if ($companylinkori <> "") { $companylink = "http://".$rowps['company_link']; } else { $companylink = ""; } $logopath = $rowps['logo_filename']; if ($companylink <> ""){ echo "<font color='#4A708B' face='arial' ><a href=$companylink style=\"color:white;text-decoration: none; \" target='new'><img src=".$logo_dir."/".$logopath." width=\"15%\"></img></a>  </font>"; } else { echo "<font color='#4A708B' face='arial' ><img src=".$logo_dir."/".$logopath." width=\"15%\"></img>  </font>"; } ?> <br> <? } echo "<br>"; } } ?> Hey all, I have a CRUD php project I am working on. I have insert working reading and deleteing. The only one I have left is update. My page submits the form but when the btn is clicked my page refreshes and does not update in the db. All the controls are cleared. Im assuming I’m missing something simple or just have a small mistake that is running past me, <?php error_reporting(E_ALL & ~E_NOTICE); // include config for Database require_once "php/config.php"; // Declare the variables that will be used. $name = $language = $datenow = ""; $nameerror = $langerror = $dateerror = ""; // Process form data when its submitted if(isset($_POST["id"]) && !empty($_POST["id"])) { // Get hidden input value. $id = $_POST["id"]; $input_name = trim($_POST["name"]); if(empty($input_name)) { $nameerror = "Name is required. "; } elseif (!filter_var($input_name, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z\s]+$/")))) { $nameerror = "Please enter a valid name. "; } else { //$namesafe = mysqli_real_escape_string($connection, $input_name); $name = $input_name; } // Validate language entered $input_lang = trim($_POST["language"]); if(empty($input_lang)) { $langerror = "Please enter a language. "; } else { $language = $input_lang; } // Get current Date and Time $currentDate = date("Y-m-d H:i:s"); // OR $datetimeobj = new DateTime(); $datetimeobj->format("Y-m-d H:i:s"); //if(empty($nameerror) && empty($langerror) && empty($dateerror)) { if($name != "" && $language != "") { $sql = "UPDATE users SET name=:name, language=:language, " . "date=:date WHERE id=:id"; error_log($sql); if($stmt = $pdoConnect->prepare($sql)) { $stmt->bindParam(":name", $param_name); $stmt->bindParam(":language", $param_lang); $stmt->bindParam(":date", $param_date); $stmt->bindParam(":id", $param_id); $para_name = $name; $param_lang = $lang; $param_date = $date; $param_id = $id; if($stmt->execute()) { header("location: index.php"); exit(); } else { echo "Something went wrong, try again later."; } } } else { $errormsg = '<div > 'All fields are required to continue</div>'; } unset($stmt); unset($pdoConnect); } else { if(isset($_GET["id"]) && !empty(trim($_GET["id"]))) { $id = trim($_GET["id"]); $sql = "SELECT * FROM users WHERE id = :id"; if($stmt = $pdoConnect->prepare($sql)) { $stmt->bindParam(":id", $param_id); $param_id = $id; if($stmt->execute()) { if($stmt->rowCount() == 1) { $row = $stmt->fetch(PDO::FETCH_ASSOC); //$id = $row["id"]; $name = $row["name"]; $language = $row["language"]; $userdate = $row["date"]; } else { header("location: error.php"); exit(); } } else { echo "Something went wrong with UPDATE, try again later."; } } // Close $stmt statement unset($stmt); // Close connection unset($pdoConnect); } else { // URL doesn't contain valid 'id' parameter. header("location: error.php"); exit(); } } ?>
Hi. So I've coded many a file upload form and never had any trouble. Until now. For some reason when I try to upload MP3 files, I'll hit submit and the page just reloads. Once it does so, the file upload field is once again blank. What's odd is that images and documents upload just fine. It's only audio tracks that cause the page to reload and clear. My php.ini max file upload size is at this point set to 100M, and the files I'm trying to upload are under 10M. Any ideas? Here's the form code, just to post it-- pretty basic. I'm at a loss here.... Any ideas would be appreciated. Thanks very much. <form action="test.php" enctype="multipart/form-data" method="POST"/> <input type = "file" name = "audio" /> <p><input type ="submit" name="submit" value="do it."/><p> </form> |