PHP - Undefined Argument Warnings
Hey all. I have a function called displayForm in a form validation script. This function accepts a few arguments but these arguments are empty upon initial calling of the function. One of the arguments is and errors array that only gets populated if there were form errors.
So upon running my script initially I get missing argument Warnings. Can these warnings simply be ignored? Would they cause problems throughout my script if I ignore these warnings? And how can I suppress these warnings if I would like to? Thanks all for your help. Cheers. Similar Tutorialsok people sorry but its late, and I'm tired and I can't figure this out maybe I just need a break? I'm getting some warnings here, first here is my code: Code: [Select] <?php echo"<?xml version=\1.0\"encoding=\UFT-8\"\x3f>"; echo"\n"; ?> <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtmll/DTD/xhtmll-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"lang="en"> <head> <title>Assignment 7: Making Space, Part 3</title> <meta name="author" content="Jim Cozzy"/> </head> <body> <h1> Assignment 7: Making Space, Part 3 </h1> <?php echo "<h2>Today is ".date('l, F d, Y')."</h2>"; ?> <?php //calculate the area of an equilateral triangle function calcTriangle($cVal) { $halfSide = $cVal/2; $otherSide = sqrt(($cVal*$cVal) - ($halfSide*$halfSide)); $areaValue = $otherSide * $halfSide; echo "<p>The area of an equilateral triangle whose sides are {$cVal} is {$areaValue}.</p>\n"; } $yeah = (isset($_POST['vfld']))?$_POST['vfld']:''; if (isset($_POST['submit'])) { if ($_POST['submit'] == "Clear") { $yeah = ""; } elseif ($_POST['submit'] == "Calculate") { if (!eregi(square|circle|triangle, $yeah)) { echo "<p>Sorry I forgot to mention the the shape needs to be a Square, Circle, or a Triangle.</p>". "<p>Please return and try again.</p>"; exit; } }} ?> <form method="post" action="makingspace3.php" id="form1" name=form1"> <p> Write down a shape and a number and I will compute the area for: <input type="text" id="vfld" name="vfld" value="<?php echo $yeah; ?>"/> </p> <p> After you have done this click calcualte to see results </p> <p> <input type="submit" name="submit" value="Calculate" /> <input type="submit" name="submit" value="Clear" /> </p> </form> <div id="footer"> <pre>This page written by: <cite>James Cozzy</cite> ©2011 and beyond</pre> </div> </body> </html> so when I enter something wrong into my form like ggggg I want it to print an error which it does, but it also says what am I missing???? Notice: Use of undefined constant square - assumed 'square' in /studfs1/homepage/CISS-225/makingspace3.php on line 49 Notice: Use of undefined constant circle - assumed 'circle' in /studfs1/homepage/CISS-225/makingspace3.php on line 49 Notice: Use of undefined constant triangle - assumed 'triangle' in /studfs1/homepage/CISS-225/makingspace3.php on line 49 Is there any way to catch warnings without defining a warning handler? Example: try { $settings = parse_ini_file( 'main.ini' ); } catch( ErrorException $e ) { throw new ErrorException('No main configuration file found for webiste', '0003'); } Only ends up throwing a warning if the file doesn't exist. I want to catch it and throw an error. Okay I have been trying to work out this problem for 3 months I am not the type of person to give up but I have tried everything. I was first not able to connect to my database live with my form but I did a change from ($cxn,$sql) to ($sql,$link) since then I was able to download to phpmyadmin in Google Chrome and no other site. But in Google Chrome I get a message about global registry Warning: Unknown on line 0. all other sites give me a Warning line 116 MySql Link is Here is my coding can someone help I have only been using PHP and I know someone is out there with much more knowledge than I have. This is the first page with the codes but it does not go to the second page which I will paste after this one. Any help would make my year better. Code: [Select] <php @session_start(); switch (@$_POST['Button']) { case "Login1": include "Connections/connect_to_mysql.php"; $sql = "SELECT id FROM Members WHERE id= '$_POST[fusername]'"; $result = mysql_query($sql) or die("Query died: fusername"); $num = mysql_num_rows($result); if($num > 0) //login name was found { $sql = "SELECT id FROM Members WHERE id='$_POST[fusername]' AND password=md5('$_POST[fpassword])'"; $result2 = mysql_query($sql) or die("Query died: fpassword"); $num2 = mysql_num_rows($result2); if($num2 > 0) //password matches { $_SESSION['email1']="yes"; $_SESSION['id'] = $_POST['fusername']; $sql = "INSERT INTO Members (id,loginTime) VALUES ('$_SESSION[id]',NOW())"; $result = mysql_query($sql) or die("Query died: insert"); header("Location: New_member.php"); } else //password does not match { $message_1="The username, '$_POST[fusername]' exists, but you have not entered the correct password! Please try again."; $fusername=strip_tags(trim($_POST['fusername'])); include("login_form.php"); } } else //username not found { $message_1 = "The username you entered does not exist! Please try again."; include("login_form.php"); } break; case "Register": /* Check for blanks */ foreach($_POST as $field => $value) { if($field != "fax") { if(empty($value)) { $blanks[] = $field; } else { $good_data[$field] = strip_tags(trim($value)); } } } if(isset($blanks)) { $message_2 = "The following fields are blank. Please enter the required information: "; foreach($blanks as $value) { $message_2 .="$value, "; } extract($good_data); include("login_form.php"); exit(); } /* validate data */ foreach($_POST as $field => $value) { if(preg_match("/name/i",$field) and !preg_match("/user/i",$field) and !preg_match("/log/i",$field)) { if (!preg_match("/^[A-Za-z' -]{1,50}$/",$value)) { $errors[] = "$value is not a valid name. "; } } if(preg_match("/email/i",$field)) { if(!preg_match("/^.+@.+\\..+$/",$value)) { $errors[]="$value is not a valid email addr."; } } } //end if not empty foreach($_POST as $field => $value) { $$field = strip_tags(trim($value)); } if(@is_array($errors)) { $message_2 = ""; foreach($errors as $value) { $message_2 .= $value." Please try again<br />"; } include("login_form.php"); exit(); } // end if errors are found /* check to see if username already exists */ include_once"Connections/connect_to_mysql.php"; $link = @mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql"); @mysql_select_db("$db_name") or die ("Query died:"); $sql = "SELECT id FROM Members WHERE id='$id'"; $result = mysql_query($sql) or die("Query died: id."); $num = mysql_num_rows($result); if($num > 0) { $message_2 = "$id already used. Select another User Name."; include("login_form.php"); exit(); } // end if username already exists else // Add new member to database { $sql = "INSERT INTO Members (id,sign_up_date,username password,firstName,lastName,email) VALUES ('$id',NOW(),,md5('$password'), '$username','$firstName','$lastName','$email')"; mysql_query($sql); $_SESSION['email1']="yes"; $_SESSION['id'] = $username; /* send email to new Customer */ $emess = "You have successfully registered. "; $emess .= "Your new username and password a "; $emess .= "\n\n\t$username\n\t"; $emess .= "$password\n\n"; $emess .= "We appreciate your interest. \n\n"; $emess .= "If you have any questions or problems,"; $emess .= " email ebermylove@gmail.com"; $subj = "Your new customer registration"; # $mailsend=mail ("$email","$subj","$emess"); } break; default: include("login_form.php"); } ?> <php session_start(); if (@$_SESSION['auth'] != "yes") { header("Location: login.php"); exit(); include("dogs.inc"); $link = mysqli_connect($host,$user,$password,$dbname) or die("Couldn't connect to server."); $sql = "SELECT firstName, lastName FROM `Members` WHERE id='{$_SESSION['id']}'"; $result = mysqli_query($sql,$link) or die("Couldn't execute query"); $row = mysqli_fetch_assoc($result); extract($row); } echo "<html> <head><title>New Member Welcome</title></head> <body> <h2 style='margin-top: .7in; text-align: center'> Welcome $firstName </h2>\n"; ?> <p>Your new Member accounts lets you enter the members only section of our web site. You'll find special discounts, a profile of matches, live advise for experts, and much more.</p> <p>Your new Member ID and password were emailed to you. Store them carefully for future use.</p> <div style="text-align: center"> <p style="margin-top: .5in; font-weight: bold"> Glad you could join us!</p> <form action="member_page.php" method="post"> <input type="submit" value="Enter the Members Only Section"> </form> <form action="profile.php" method="post"> <input type="submit" value="Go to Main Page"> </form> </div> </body> </html> Howdy, 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 I use PHP's PDO extensively for data grabbing and inserting. When I am selecting data, the return is a PHP PDO object which in itself contains select statements. So I use foreach to parse through the object and build a table. For cells which I have data it's fine but for cells which do not get any data meaning that have no entry in the db, php throws out a error PHP Warning: Invalid argument supplied for foreach(). I tried using if(is_array) and also @ to suppress them but no luck . Can anyone point me to the right direction for suppressing these errors/warnings!! In php.ini on my local development server, error_reporting is set to Quote error_reporting = E_ALL | E_STRICT And I get no errors. However, on the remote web server I found a bunch of warnings in the error log. I fixed most of them, but this error/warning should have popped up on my development console: Quote [02-Dec-2011 17:47:22] PHP Warning: array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in /home/bpslk/public_html/cart-checkout.php on line 177 [02-Dec-2011 17:47:22] PHP Warning: Invalid argument supplied for foreach() in /home/bpslk/public_html/cart-checkout.php on line 177 I can fix the code to eliminate the warning, no prob. But why am I NOT seeing this error on my development machine? --Thanks --HarryG Hello, I was trying out some code to check out how some of the php settings work and when i tried allow_call_time_pass_reference to see if it works, it doesn't spew out any warning or error like the comments in the .ini file mention (or in the manual sites). Maybe i'm not using some other setting in order to see this? Here is my EXACT code. <?php ini_set('display_errors',1); error_reporting(-1); $variable = 'String'; function display($variable) { return $variable; } echo display(&$variable); ?> Outputs : String. No errors, no warnings. I'm running PHP Version 5.3.2-1ubuntu4.5 Hello, I have just upgraded my wampserver and with it MySQL, PHP and PhpMyAdmin versions. And my scripts, which ran normally before, not burst hundreds of undefined variable and undefined index notices. I realize it's "notices", not "errors" but this is quite irritating. I believe it might be due to some upgrade in PHP scripting rules or something but I don't know what. I hope you can help me. The first type of notice is "undefined variable". This function will return the notice if I remove the bold red line, where I define the variable as empty before I use it in the loop. I didn't need to do this before. function statistics($array) { [color=red][b]$list = '';[/b][/color] if(is_array($array)) { foreach($array as $name => $value) { // Rip out the name of the client. $list .= "<li>".$name." - "; // set an integer so we know how many tier2 values we have read. $x = 0; foreach($value as $difference => $sum_total) { // if this is the more than the first tier2 values, use a '+' between the units. $list .= (++$x > 1) ? " + ".$sum_total." ".$difference : $sum_total." ".$difference; } // close the line out. $list .= "</li>"; } } return $list; } To avoid the 10+ like notices on the page I declare them empty before the variable's first occurrence. But this sounds stupid to me. Wasn't this one of PHP's benefits, not to have to declare the variable before using it? I also get about 30+ undefined index notices, e.g. Quote Notice: Undefined index: COMPANY XXX in F:\wamp\www\Project Management\main.php on line 37 Notice: Undefined index: USD in F:\wamp\www\Project Management\main.php on line 37 Notice: Undefined index: USD in F:\wamp\www\Project Management\main.php on line 41 Here are those lines: $income_total = calculate("income"); foreach($income_total as $row) { $clientID = $row['clientID']; $clientname = $row['clientname']; //$client = "<a href=\"index.php?page=Client&do=view&clientID=$clientID\">".$clientname."</a>"; $client = "<a href=\"index.php?page=Project&do=view&sortby=$clientID\">".$clientname."</a>"; $currency = $row['currency']; $client_sum = $row['client_sum']; $year_sum = ''; $year_sum += $client_sum; $income = ''; $income[$client][$currency] += $client_sum; $income_list = statistics($income); $income_all = ''; $income_all[$currency] += $client_sum; } Line 37 is: Quote $income[$client][$currency] = It's the values assigned to $client and to $currency that seem to cause the notice. How do I deal with this? I don't just want to turn error/notice display off, I want to resolve this issue. my current code: Code: [Select] $Townsearch = $_REQUEST['rsTown']; list($Town, $County) = split('[,]', $Townsearch); ltrim($County,1); I am getting undefined index and undefined offset, so I tried this: Code: [Select] if $_REQUEST['rsTown'] == ''{ $Townsearch = ''; } else { $Townsearch = $_REQUEST['rsTown']; } but this brought back: Parse error: syntax error, unexpected T_VARIABLE, expecting '(' in D:\retroandvintage.co.uk\wwwroot\main.php on line 6 Can someone please help? thanks I am pretty sure I defined these, by making it something like $blah="blah" and `blah` = ' {$blah}' So why am I getting these errors = Notice: Use of undefined constant petid - assumed 'petid' in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 38 Notice: Use of undefined constant adopter - assumed 'adopter' in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 41 Notice: Undefined variable: fulldate in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 44 Fatal error: Call to undefined function showpet_forum() in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 45 $time = mysql_query("SELECT * FROM `pets_adopted`"); $date = mysql_fetch_array($time); $fulldate = "$date[fulldate]"; $halfdate = "$date[halfdate]"; function check(){ $pid = mysql_real_escape_string($_GET['id']); $result = mysql_query("SELECT * FROM `pets_adopted` WHERE `id` = '{$pid}'"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $results = mysql_query("SELECT * FROM `pets_list` WHERE `id` = '{$row[petid]}'"); $pet = mysql_fetch_array($results); $results2 = mysql_query("SELECT * FROM `users` WHERE `id` = '{$row[adopter]}'"); $usercc = mysql_fetch_array($results2); There's the snippet. Thank you for any help. I am just really lost. please help! I am getting undefined index and offset when I duplicated my SEARCH page for when logged in here is my code Code: [Select] <?php include_once("config.php"); include_once("functions.php"); // Check user logged in already: checkLoggedIn("yes"); ?> <!doctype html> <html> <head> <title>Retro and Vintage</title> <meta name="description" content="xxx" /> <meta name="keywords" content="xxx" /> <meta name="Content-Language" content="en-gb" /> <meta name="robots" content="FOLLOW,INDEX" /> <meta name="revisit-after" content="2 days" /> <meta name="copyright" content="jbiddulph.com" /> <meta name="author" content="John Biddulph - Professional web site design and development in the south of england mainly worthing and brighton" /> <meta name="distribution" content="Global" /> <meta name="resource-type" content="document" /> <link rel="stylesheet" type="text/css" href="css/reset.css" /> <link rel="stylesheet" type="text/css" href="css/style.css" title="default" /> <link rel="alternate stylesheet" type="text/css" href="css/style1.css" title="1" /> <link rel="alternate stylesheet" type="text/css" href="css/style2.css" title="2" /> <script type="text/javascript" src="js/stylechanger.js"></script> <script type="text/javascript" src="js/jquery-1.2.1.pack.js"></script> <script type="text/javascript"> function lookup(inputString) { if(inputString.length == 0) { // Hide the suggestion box. $('#suggestions').hide(); } else { $.post("rpc.php", {queryString: ""+inputString+""}, function(data){ if(data.length >0) { $('#suggestions').show(); $('#autoSuggestionsList').html(data); } }); } } // lookup function fill(thisValue) { $('#inputString').val(thisValue); setTimeout("$('#suggestions').hide();", 200); } </script> </head> <body> <?php if($messages) { displayErrors($messages); }?> <header> <div id="title"> <h1>My Pub Space <a href="#" onClick="setActiveStyleSheet('default'); return false;"><img src="images/0.gif" width="15" height="15" border="0" alt="css style" /></a> <a href="#" onClick="setActiveStyleSheet('1'); return false;"><img src="images/1.gif" width="15" height="15" border="0" alt="css style" /></a> <a href="#" onClick="setActiveStyleSheet('2'); return false;"><img src="images/2.gif" width="15" height="15" border="0" alt="css style" /></a> <span> <form method="post" class="textbox" action="search1.php"> City/Town: <input type="text" size="26" class="searchbox" value="" id="inputString" onKeyUp="lookup(this.value);" onBlur="fill();" /> <div class="suggestionsBox" id="suggestions" style="display: none;"> <img src="images/upArrow.png" style="position: relative; top: -36px; left: 105px; z-index:1;" alt="upArrow" /> <div class="suggestionList" id="autoSuggestionsList"> </div> </div> <input type="image" src="images/go.png" height="30" with="30" value="GO" /> </form> </span> </h1> </div> </header> <nav> <ul> <li class="selected"><a href="#">Home</a></li> <li><a href="#">Pubs</a></li> <li><a href="#">Members</a></li> <li><a href="#">Events</a></li> <li><a href="#">Register</a></li> </ul> </nav> <section id="intro"> <header> <h2>Your social guide to going down the pub, online!</h2> </header> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.</p> <img src="images/pub.jpg" alt="pub" /> </section> <div id="content"> <div id="mainContent"> <section> <article class="blogPost"> <header> <h2>This is the title of a blog post</h2> <p>Posted on <time datetime="2009-06-29T23:31+01:00">June 29th 2009</time> by <a href="#">Mads Kjaer</a> - <a href="#comments">3 comments</a></p> </header> <?php // drop out of PHP mode to display the plain HTML: $Townsearch = $_GET['rsTown']; echo $Townsearch; // Delimiters may be slash, dot, or hyphen list($Town, $County) = split('[,]', $Townsearch); $tableName="pubs"; $targetpage = "search1.php"; $limit = 20; $query = "SELECT COUNT(*) as num FROM $tableName WHERE rsTown LIKE '$Town%'"; $total_pages = mysql_fetch_array(mysql_query($query)); $total_pages = $total_pages['num']; $stages = 3; $page = mysql_escape_string($_REQUEST['page']); if( isset($_REQUEST['page']) && ctype_digit($_REQUEST['page']) ) { $page = (int) $_GET['page']; $start = ($page - 1) * $limit; }else{ $start = 0; } // Get page data $query1 = "SELECT * FROM $tableName WHERE rsTown LIKE '$Town%' LIMIT $start, $limit"; $result = mysql_query($query1); // Initial page num setup if ($page == 0){$page = 1;} $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total_pages/$limit); $LastPagem1 = $lastpage - 1; $paginate = ''; if($lastpage > 1) { $paginate .= "<div class='paginate'>"; // Previous if ($page > 1){ $paginate.= "<a href='$targetpage?page=$prev'>previous</a>"; }else{ $paginate.= "<span class='disabled'>previous</span>"; } // Pages if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } } elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few? { // Beginning only hide later pages if($page < 1 + ($stages * 2)) { for ($counter = 1; $counter < 4 + ($stages * 2); $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } $paginate.= "..."; $paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>"; $paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>"; } // Middle hide some front and some back elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2)) { $paginate.= "<a href='$targetpage?page=1'>1</a>"; $paginate.= "<a href='$targetpage?page=2'>2</a>"; $paginate.= "..."; for ($counter = $page - $stages; $counter <= $page + $stages; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } $paginate.= "..."; $paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>"; $paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>"; } // End only hide early pages else { $paginate.= "<a href='$targetpage?page=1'>1</a>"; $paginate.= "<a href='$targetpage?page=2'>2</a>"; $paginate.= "..."; for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } } } // Next if ($page < $counter - 1){ $paginate.= "<a href='$targetpage?page=$next'>next</a>"; }else{ $paginate.= "<span class='disabled'>next</span>"; } $paginate.= "</div>"; } echo $total_pages.' Results'; // pagination echo $paginate; ?> <ul> <?php while($row = mysql_fetch_array($result)) { echo '<li>'.$row['rsPubName'].', '.$row['rsTown'].', '.$row['rsCounty'].'</li>'; if ($_SESSION["rsUser"] == "admin") { echo "<a href=\"edit.php?PUBID=".$row['PubID']."\" class=\"small\">edit this pub</a>"; } } ?> </ul> </article> </section> <section id="comments"> <h3>Comments</h3> <article> <header> <a href="#">George Washington</a> on <time datetime="2009-06-29T23:35:20+01:00">June 29th 2009 at 23:35</time> </header> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.</p> </article> <article> <header> <a href="#">Benjamin Franklin</a> on <time datetime="2009-06-29T23:40:09+01:00">June 29th 2009 at 23:40</time> </header> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.</p> </article> <article> <header> <a href="#">Barack Obama</a> on <time datetime="2009-06-29T23:59:00+01:00">June 29th 2009 at 23:59</time> </header> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.</p> </article> </section> <form action="#" method="POST" method="post"> <h3>Post a comment</h3> <p> <label for="name">Name</label> <input name="name" id="name" type="text" required /> </p> <p> <label for="email">E-mail</label> <input name="email" id="email" type="email" required /> </p> <p> <label for="website">Website</label> <input name="website" id="website" type="url" /> </p> <p> <label for="comment">Comment</label> <textarea name="comment" id="comment" required></textarea> </p> <p> <input type="submit" value="Post comment" /> </p> </form> </div> <aside> <section> <header> <h3>Members Login Area</h3> </header> <h4>Welcome <? print($_SESSION["rsUser"]); ?></h4> <a href="logout.php">Logout</a> </section> <section> <header> <h3>Archives</h3> </header> <ul> <li><a href="#">December 2008</a></li> <li><a href="#">January 2009</a></li> <li><a href="#">February 2009</a></li> <li><a href="#">March 2009</a></li> <li><a href="#">April 2009</a></li> <li><a href="#">May 2009</a></li> <li><a href="#">June 2009</a></li> </ul> </section> </aside> </div> <footer> <div> <section id="about"> <header> <h3>About</h3> </header> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco <a href="#">laboris nisi ut aliquip</a> ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> </section> <section id="blogroll"> <header> <h3>Blogroll</h3> </header> <ul> <li><a href="#">NETTUTS+</a></li> <li><a href="#">FreelanceSwitch</a></li> <li><a href="#">In The Woods</a></li> <li><a href="#">Netsetter</a></li> <li><a href="#">PSDTUTS+</a></li> </ul> </section> <section id="popular"> <header> <h3>Popular</h3> </header> <ul> <li><a href="#">This is the title of a blog post</a></li> <li><a href="#">Lorem ipsum dolor sit amet</a></li> <li><a href="#">Consectetur adipisicing elit, sed do eiusmod</a></li> <li><a href="#">Duis aute irure dolor</a></li> <li><a href="#">Excepteur sint occaecat cupidatat</a></li> <li><a href="#">Reprehenderit in voluptate velit</a></li> <li><a href="#">Officia deserunt mollit anim id est laborum</a></li> <li><a href="#">Lorem ipsum dolor sit amet</a></li> </ul> </section> </div> </footer> </body> </html> error lies on these lines Code: [Select] // drop out of PHP mode to display the plain HTML: $Townsearch = $_GET['rsTown']; echo $Townsearch; // Delimiters may be slash, dot, or hyphen list($Town, $County) = split('[,]', $Townsearch); hi, I need help really badly for my PHP-Postcard Script. Basically it sends the card out but the URL does not work, I get the following error message: The URL is not valid and cannot be loaded It also states that Notice: Undefined index: www.voluntary.awardspace.co.uk in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 25 Notice: Undefined index: Postcard.php in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 25 See Code below: <?php session_start(); //check error log ini_set('display_errors', 1); ini_set('log_errors', 1); ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); error_reporting(E_ALL); // CHANGE PARAMETERS HERE BEGIN $senderName = " Holidays From Home "; // Eg.: John's Postcards $senderEmail = "chris01@voluntary.awardspace.co.uk"; // Eg.: john@postcard.com // Change only if you have problems with urls $postcardURL = "http://".$_SERVER["www.voluntary.awardspace.co.uk"].$_SERVER["Postcard.php"]; // CHANGE PARAMETERS HERE END $result = 0; $msg = ""; $msg1 = ""; $pic = ""; function displayPhotos() { global $pic; $columns = 5; $act = 0; $act1 = 0; // Open the actual directory if($handle = opendir("thumbs")) { // Read all file from the actual directory while($file = readdir($handle)) { if(!is_dir($file)) { if(isset($pic[1])) { if($pic[1] == $act1){$sel = "checked";} else{$sel = "unchecked";} } if($act == 0){echo "<tr>";} echo "<td align='center'><img src='thumbs/$file' alt='postcard'/><br/><input type='radio' name='selimg' value='$file,$act1' $sel/></td>"; $act++; $act1++; if($act == $columns){$act = 0;echo "</tr>";} } } echo "</tr>"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <head> <title>Micro Postcard</title> <link href= "style/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="main"> <div class="style1" id="caption"> <div align="left" class="style1"></div> </div> <?php //makes sure form is correctly filled in if(!empty($_POST["submit"])) { if(empty($_POST["selimg"])){$msg = "Please select an image from above!";$result = 3;} else{$pic = explode(",",$_POST["selimg"]);} if(empty($_POST["email"]) && empty($result)){$msg1 = "You must enter an email address!";$result = 3;} $secCode = empty($_POST["secCode"]) ? "" : strtolower($_POST["secCode"]); if($secCode == $_SESSION["securityCode"] && $result != 3) { $filename = date("YmdGis"); $f = fopen("messages/".$filename.".txt","w+"); fwrite($f,$pic[0]."\n"); fwrite($f,$_POST['email']."\n"); fwrite($f,stripslashes($_POST["message"])."\n"); fclose($f); // Compose the mail $from = "From: $senderName <$senderEmail>\r\n"; $replay = "Reply-To: $senderEmail\r\n"; $params = "MIME-Version: 1.0\r\n"; $params .= "Content-type: text/plain; charset=iso-8859-1\r\n"; $mailtext = "You have just received a Virtual Postcard!\r\n\r\n You can pick up your postcard at the following web address:\r\n $postcardURL?show=$filename\r\n\r\n We hope you enjoy your postcard, and if you do, please take a moment to send a few yourself!\r\n\r\n Regards,\r\n Holidays From Home\r\n $postcardURL"; // Send email @mail($_POST["email"],"You've received a postcard",$mailtext,$from.$replay.$params); echo "<center> Your postcard was sent successfully!<br /><br /> <img src='images/$pic[0]' alt='postcard' /><br /><br /><br />".stripslashes($_POST["message"]). "</center>"; $result = 1; } else{if($result != 3){$result = 2;}} } if(!empty($_GET["show"])) { $file = $_GET["show"]; $content = file("messages/$file.txt"); $pic = $content[0]; unset($content[0]); unset($content[1]); foreach($content as $value){$main .= $value;} echo "<center> Your postcard!<br /><br /> <img src='images/$pic' alt='postcard' /><br /><br /><br />$main </center>"; } if((empty($result) || $result == 2 || $result == 3) && empty($_GET["show"])) { echo "<form action='#' method='post'> <table align='center'>"; displayPhotos(); echo "</table> <div style='color:#f00;font-size:16px;'>$msg</div> <h2>Fill in the Form and then click on Send Card!!</h2> <table width='100%'> <tr><td>Send to (email address):</td><td><div style='color:#f00;font-size:16px;'>$msg1</div><input type='text' name='email' size='30' value='".$_POST["email"]."' /></td></tr> <tr><td>Message:</td><td><textarea name='message' rows='10' cols='40'>".stripslashes($_POST["message"])."</textarea></td></tr> <tr><td colspan='2'>".($result == 2 ? "<p style='color:#f00;font-size:16px;'>Sorry the security code is invalid! Please try it again!</span></p>" : " ")."</tr> <tr> <td>Security code: <input class='text' name='secCode' type='text' size='10' /> </td><td><img src='securityCode.php' alt='security code' border='1' /></td> </tr> <tr><td colspan='2'> </tr> <tr><td colspan='2' align='left'><input type='submit' value='Send card!' name='submit'/></td></tr> </table> </form>"; } ?> Absolutely any help would be much appreciated. I want ot know is there a way round this problem? Here is the http://voluntary.awardspace.co.uk/Postcard.php I am absolutely desperate to solve this burning issue Hi all, I don't know php, but i have a script i would like to be able to also run from shell, like: "php script arg1"... if (isset($_SERVER['argc'])) { $postip = $1; } else { $postip = $_POST["ip"]; } How do i assign $postip = $1; (or is it infact $2...) ? My script gives me this error now: PHP Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' Thanks in advance :-) ! For some reason I keep getting a recurring error every time someone uses a page on my site. Here is the error: Code: [Select] [Date] PHP Warning: array_key_exists() [<a href='function.array-key-exists'>function.array-key-exists</a>]: The second argument should be either an array or an object in /home/page.php on line 52 The offending line is he Code: [Select] echo array_key_exists($i, $alpha) ? '<li><a href="?a=show&letter='.$i.'&type='.$type.'">'.$i.'</a></li> ' : '<li class="no_highlight">'.$i.'</li> The code works, but the error message must be showing that I am performing the echo incorrectly. Anyone have any ideas on where I could be going wrong (other than the exact line, that is )? Here's the rest of the code for full reference (the offending line is near the top). Thanks for any help! Code: [Select] <?php $sql = "SELECT *, UPPER(SUBSTRING(series,1,1)) AS letter FROM design WHERE type = '$type' ORDER BY series"; $query = mysql_query($sql) or die(mysql_error()); // Display a range of letters. echo '<ul class="alphabet">'; while ($records = mysql_fetch_assoc($query)) { $alpha[$records['letter']] += 1; ${$records['letter']}[$records['series']] = $records['series']; } foreach(range('A','Z') AS $i) { echo array_key_exists($i, $alpha) ? '<li><a href="?a=show&letter='.$i.'&type='.$type.'">'.$i.'</a></li> ' : '<li class="no_highlight">'.$i.'</li> '; echo $i != 'Z' ? ' ':'</ul>'; } // Display records of the letter selected. if (isset($_GET['letter']) && !empty($_GET['letter']) && !is_numeric($_GET['letter'])) { $letter = substr($_GET['letter'], 0, 1); } else { $letter = ''; } $a = (isset($_GET['a'])) ? strip_tags(trim(htmlentities($_GET['a'], ENT_QUOTES))) : 'index'; switch ($a) { case 'index': $select_series = mysql_query("SELECT *, UPPER(SUBSTRING(series,1,1)) AS letter FROM design WHERE `type` = '$type' ORDER BY `id` DESC LIMIT 8") or die (mysql_error()); $i=3; echo '<h3>Newest Additions</h3>'; while($row2 = mysql_fetch_array($select_series)) { extract ($row2); $contents_here = '<div class="envelope"><a href="?a=show&letter='.$letter.'&type='.$type.'#'.$title.'"><img src="previews/'.$id.'.jpg" class="tips" title="'.$title.'|'.$series.'"><br>'.$title.'</a></div>'; if ($i==0) { echo ''.$contents_here.''; } else if ($i==3) { echo ''.$contents_here.''; } else { echo ''.$contents_here.''; } $i++; $i=$i%3; } break; case 'show': $letter2 = (isset($_GET['letter'])) ? strip_tags(trim(htmlentities($_GET['letter'], ENT_QUOTES))) : ''; $sql = "SELECT * ,UPPER(SUBSTRING(series,1,1)) AS letter, date_format(design.datetime, '%M %d, %Y') AS datetime FROM design WHERE series LIKE '$letter2%' AND type = '$type' ORDER BY series ASC, id ASC"; $query = mysql_query($sql) or die (mysql_error()); echo '<h3><a name="'.$i.'"><b>'.$letter.'</b></a></h3> <table align="center" width="100%"><tr><td>'; $series = ''; while ($row = mysql_fetch_assoc($query)) { $image = $row[image]; $datetime = $row[datetime]; $id = $row[id]; $type = $row[type]; $title = $row[title]; $count_display = $row[count_display]; if ($series != $row['series']) { //Assign category to holding var $series = $row['series']; //echo Category heading echo '<h3><a href="#" class="top"></a>'.$series.'</h3> '; } echo '<table align="center" class="format" cellpadding="0" cellspacing="0"> <tr><td> <img src="previews/'.$id.'.jpg" align="right"> <td class="design"><ul class="design_info"> <li class="special"><b>Title:</b> <a name="'.$title.'">'.$title.'</a> <ul> <li><b>Series:</b> '.$series.' <li><b>Type:</b> '.$type.' <li><b>Uploaded:</b> '.$datetime.' <li><b>Downloads:</b> '.$count_display.' </ul></ul> <ul class="design_dl"> <li class="preview"><a href="graphics/preview.php?id='.$id.'" target="_blank">preview</a> <li class="download"><a href="graphics/download.php?id='.$id.'">download</a> </ul> </td></tr> </table>'; } } echo '</table>'; ?> Hi, I am attempting to export some table data to an excel spreadsheet. I am having trouble with the final few lines and getting the following error within the spreadsheet (which is otherwise working well). Quote The argument should be an array in/home/website/public_html/student_list_export.php on line 34 I get the same error message for the line below also (echo implode("\t", array_values($row)) . "\n". I'm at a loss. This seems like a pretty obvious and direct error message but I can't get it working properly. Can somebody please help me? Below is the code I am working with. <?php include('includes/admin_session.php'); require_once("includes/connection.php"); function cleanData(&$str) { $str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $str); if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; } // file name for download $filename = "student_list_" . date('Ymd') . ".xls"; header("Content-Disposition: attachment; filename=\"$filename\""); header("Content-Type: application/vnd.ms-excel"); $flag = false; $result = mysqli_query($connection,"SELECT * FROM students ORDER BY tutor") or die(mysqli_error($connection)); while(false !== ($row = mysqli_fetch_assoc($result))) { if(!$flag) { // display field/column names as first row echo implode("\t", array_keys($row)) . "\n"; $flag = true; } array_walk($row, 'cleanData'); echo implode("\t", array_values($row)) . "\n"; } ?> Hello, i know this is a very silly question but it bothers me to know the reasoning behind it. My application has a design where the functions are stored in functions.php and variables are stored in variables.php. There are some functions that have variables that i might change often and the reason i don't directly use them in the argument itself is so that in future if i have to change the default argument's value , then i wouldn't have to scroll through all the functions and look for it. I have a slippery memory i know i will be able to remember it better if i store custom global variables separately and custom global functions separately. I tried searching these forums for this but its giving me a message like "search daemon not found" or something like that.. Anyways , coming to the point, i know that PHP doesn't accept variables as default arguments but may i know the reasoning behind this? If i understand the reasoning behind this i know it will stick better in my head.So..why does a function not allow a variable as a default value? Or if anyone has a link to explaining this behaviour in PHP, i would appreciate it if you could pass it on! Thank you I've been challenging myself to get the system() argument working for the past hour and something. I still can't get it working so I ask for assistance. system ("cp /var/www/http/test.com/products/".$fordir['fordir']."/".$category['category']."/".$_POST['id']." /home/n/Documents/My\ Sites/test.com\ codebase"); The error log doesn't say anything, so I suspect that PHP is not even attempting to parse the code. Can anyone spot something that shouldn't be the way it is? How do I make my constructor work when I don't pass in an argument. That is, it should efault to null. Code: [Select] class Something{ private $type=null; public function __construct($t){ $this->type = $t; } public function setSomething($t){ $this->type = $t; } public function getSomething(){ if (is_null($this->type)) { return "None for you!"; } else { return "Something is " . $this->type . "."; } } } TomTees I'm getting this error, but I'm not sure how to fix it (on my Wordpress site). Warning: usort() [function.usort]: The argument should be an array in /home2/lushwebs/public_html/4mulaevents/wp-content/themes/dailyedition/includes/talking-points.php on line 20 Warning: Invalid argument supplied for foreach() in /home2/lushwebs/public_html/4mulaevents/wp-content/themes/dailyedition/includes/talking-points.php on line 22 Any help appreciated. Thanks! |