PHP - Another Undefined Index And Undefined Offset?!
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); Similar Tutorialsmy 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 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. 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
I am having undefined offset:2 and any body can give me an idea, why i get this error message.
for($i = 0; $i< count($from_branch) || $i< count($to_branch) || $i< count($quantity) || $i< count($prio_color); $i++) { $query = mysql_query("INSERT INTO pull_out(`description`,`barcode`,`from`,`to`,quantity,prio_color,date_created,remarks,userid) VALUES('$desc','$barc','$from_branch[$i]','$to_branch[$i]','$quantity[$i]','$prio_color[$i]','$datec','$remar','$userid')"); }and i use checkbox under prio_color and i think this is the cause, I have the following code: Code: [Select] <?php $lines = count(file("input.txt")); $file = fopen("input.txt", "r"); for($i=0; $i<=$lines; $i++) { $friend = fgets($file); $friendInfo = explode(" ", $friend); $friendID[$i] = $friendInfo[0]; $friendLAT[$i] = $friendInfo[1]; $friendLONG[$i] = $friendInfo[2]; echo $friendInfo[2]; echo $friendLAT[$i]; } fclose($file); ?> The value of $friendInfo[2]; and $friendLAT[$i]; echo out alright. However I get the following output: Quote 0.0 0.0-10.1 10.112.2 -12.238.3 38.3179.9979.99 Notice: Undefined offset: 1 in C:\inetpub\wwwroot\test.php on line 18 Notice: Undefined offset: 2 in C:\inetpub\wwwroot\test.php on line 19 Notice: Undefined offset: 2 in C:\inetpub\wwwroot\test.php on line 21 It doesn't make any sense to me, I can assign the value of the array to a variable ($friendLAT[$i], but it says the offset is undefined. Hello, my script worked great with no errors until I had to migrate to a new server, which is using cpanel/WHM, I have run Apache update and ensured curl is installed but I keep getting this in the error log. Here is part of the code, the error is PHP Notice: Undefined offset: 2 in /home/username/public_html/control/ajax/actions/currently_playing.php on line 59 and here is that section of code (line 59 is labled) Code: [Select] // Diaplays when sever is online but no song title } else { $title = str_replace('\'', '`', $split[6]); $title = str_replace(',', ' ', $title); $title = "$title"; // Diaplays song } } if($title) { $tmp = explode(" - ", $title); $artist = trim(str_replace("`", "'", $tmp[0])); $album = trim(str_replace("`", "'", $tmp[1])); $title = trim(str_replace("`", "'", $tmp[2])); //LINE 59 HERE $request = $this->albumGetInfo($artist, $album); $img = $request["album"]["image"][1]["#text"]; When I enable error_reporting this notice appear: Notice: Undefined offset: 1 This is code: function get_value_of($name) { $lines = file("../config.php"); $val = array(); foreach (array_values($lines) AS $line) { list($key, $val) = explode('=', trim($line) ); if (trim($key) == $name) { $val = convEnt($val); return $val; } } return false; } Error is in this line: list($key, $val) = explode('=', trim($line) ); How to fix this? hi... i'm getting an undefined offset for the associative arrays [28-46] in this format. $sql="INSERT INTO tableName (name1, name2, name3, name4... this goes all the way to name46) VALUES ('".$data[0]."', '".$data[1]."', '".$data[2]."', '".$data[3]."' ...this goes all the way to name46)"; $sqlData = mysql_query($sql); i have read that i can prevent the notices by doing the following, but it's not working for me: $sql="INSERT INTO tableName ( 'name1' => "isset(.$data[0].) ? $data[0] : 'default value'", 'name2' => "isset(.$data[1].) ? $data[1] : 'default value'", 'name3' => "isset(.$data[2].) ? $data[2] : 'default value'", 'name4' => "isset(.$data[3].) ? $data[3] : 'default value'", #this goes all the way to name46 )"; $sqlData = mysql_query($sql); can anyone please assist me? Hi, I'm testing my PHP in the console and was wondering what this means? PHP Notice: Undefined offset: 1 Is it a warning or an error? My code... Code: [Select] $form_submission = "brother"; $lines = file('eo_dic.txt'); if ($form_submission == null){ // Sanitization. echo 'Text field is empty!'; exit; } foreach ($lines as $line) { list($field1, $field2) = preg_split('/=/', $line); // back slash might not be needed if (stristr($field1, $form_submission) || stristr($field2, $form_submission)){ echo $field1 . ' = ' . $field2; } } The results and error... Code: [Select] Brother = frato Brotherhood = frateco Brotherly = frata PHP Notice: Undefined offset: 1 in /home/asdf/Dev/Projects/eo_translate/script_part2.php on line 50 PHP Notice: Undefined offset: 1 in /home/asdf/Dev/Projects/eo_translate/script_part2.php on line 50 PHP Notice: Undefined offset: 1 in /home/asdf/Dev/Projects/eo_translate/script_part2.php on line 50 PHP Notice: Undefined offset: 1 in /home/asdf/Dev/Projects/eo_translate/script_part2.php on line 50 Line 50 = list($field1, $field2) = preg_split('/=/', $line); Google has failed me once again . I'm getting this error, which I can't find out how to fix: Here's the code: $Database_Factions = "factions"; $Database_Factions_1 = "Name"; $Database_FName_Num = 1; $searchmemberdata = mysql_query("SELECT " . $Database_Factions_1 . " FROM " . $Database_Factions . " WHERE " . $Database_Factions_1 . " LIKE '" . mysql_real_escape_string($_GET['name']) . "%' LIMIT 1"); $searchdata = mysql_fetch_row($searchmemberdata); echo($searchdata[$Database_FName_Num]); echo("<meta http-equiv='refresh' content='55;url=member.php?action=ViewFaction&name=" . $searchdata[$Database_FName_Num] . "' />"); I know my code is not optimized, I'm fixing it after i'm done with what i'm doing. Everytime $searchdata[$Database_FName_Num] is called, the error: Notice: Undefined offset: 1 comes out. Any help? while i am coding to find text between some html tags ,, am getting an error... Notice: Undefined offset: 1 in D:\xamp\xampp\htdocs\file\dash.php on line 48 my code is at line 47 and 48 is Code: [Select] preg_match('/<td class="trow1" rowspan="3" valign="top">(.*)<\/td> /',$dat,$regs); echo $etc=$regs[1]; i am thinking copy data from Code: [Select] </td> <td class="trow1" rowspan="3" valign="top"> Posts per day: <strong>6.03</strong><br /> Threads per day: <strong>3.78</strong><br /> Members per day: <strong>4.76</strong><br /> Posts per member: <strong>1.27</strong><br /> Replies per thread: <strong>0.6</strong> </td> </tr> this much Code: [Select] Posts per day: <strong>6.03</strong><br /> Threads per day: <strong>3.78</strong><br /> Members per day: <strong>4.76</strong><br /> Posts per member: <strong>1.27</strong><br /> Replies per thread: <strong>0.6</strong> Ok, I am sure you have all come across this error before. I am trying to understand why this occurs in a straight forward (spelled out for the complete dumb ass) kind of way. I made the most simple script I could come up with that would produce the error, but I am still uncertain as to what causes it, or what the fix is. Here is the script. Using all the letters and numbers available I print the total characters in the string, run a for statement to print out each character in order from the string index, and get the error "Undefined String Offset 36". Which is the total number of characters in the string starting at 0. The test script can be accessed at the following url: http://icca.exiled-alliance.com/classtest.php $test = "abcdefghijklmnopqrstuvwxyz1234567890"; $b = "<br />"; echo $test; echo $b; echo "There are " .strlen($test). " characters in the above string"; echo $b; for($x=0;$x<=strlen($test);$x++){ echo $test[$x]. "-->number $x"; echo $b; } Can anyone clear up why that error pops up from the way I have this scripted. I get an undefined offset error when i try and call the array i made i know very little so I'm stuck and i don't know what to do Code: [Select] <?php $file = fopen("playerstats.csv","r"); $data = array(); while (($csv_line = fgetcsv($file, 0, ";")) !== FALSE) { echo $csv_line; $number = $csv_line[0]; $name = $csv_line[1]; $half = $csv_line[2]; $goals = $csv_line[3]; $assists = $csv_line[4]; $SOG = $csv_line[5]; $shots = $csv_line[6]; $fouls = $csv_line[7]; $yellow = $csv_line[8]; $yellowred = $csv_line[9]; $red = $csv_line[10]; $CK = $csv_line[11]; $saves = $csv_line[12]; $data[] = array( 'name' => $name, 'half' => $half, 'goals' => $goals, 'assists' => $assists, 'sog' => $SOG, 'shots' => $shots, 'fouls' => $fouls, 'yellow' => $yellow, 'yellowred' => $yellowred, 'red' => $red, 'ck' => $CK, 'saves' => $saves ); } ?> <!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=utf-8" /> <title>Untitled Document</title> </head> <body> <table><tr><td>Number: </td><td><?php echo $data[0];?></td></tr></table> </body> </html> Hi everyone... please help me with this. I have a gallery that I am working on. Part of that are two files upload.php and preupload.php which upload pics. And it does its job successfully BUT it shows an error 'Notice: Undefined offset: 9 in C:\wamp\www\upload.php on line 34' My line 34 is Code: [Select] if($photos_uploaded['size'][$counter] > 0). My whole code for the upload.php is <?php include("config.inc.php"); // initialization $result_final = ""; $counter = 0; // List of our known photo types $known_photo_types = array( 'image/pjpeg' => 'jpg', 'image/jpeg' => 'jpg', 'image/gif' => 'gif', 'image/bmp' => 'bmp', 'image/x-png' => 'png' ); // GD Function List $gd_function_suffix = array( 'image/pjpeg' => 'JPEG', 'image/jpeg' => 'JPEG', 'image/gif' => 'GIF', 'image/bmp' => 'WBMP', 'image/x-png' => 'PNG' ); // Fetch the photo array sent by preupload.php $photos_uploaded = $_FILES['photo_filename']; // Fetch the photo caption array $photo_caption = $_POST['photo_caption']; while( $counter <= count($_FILES['photo_filename']['tmp_name']) ) { if($photos_uploaded['size'][$counter] > 0) { if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types)) { $result_final .= "File ".($counter+1)." is not a photo<br />"; } else { mysql_query( "INSERT INTO gallery_photos( `photo_filename`, `photo_caption`, `photo_category` ) VALUES( '0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."')" ) or die(mysql_error() . 'Photo not uploaded'); $new_id = mysql_insert_id(); $filetype = $photos_uploaded['type'][$counter]; $extention = $known_photo_types[$filetype]; $filename = $new_id.".".$extention; mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" ); // Store the orignal file copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$filename); // Let's get the Thumbnail size $size = GetImageSize( $images_dir."/".$filename ); if($size[0] > $size[1]) { $thumbnail_width = 200; $thumbnail_height = (int)(200 * $size[1] / $size[0]); } else { $thumbnail_width = (int)(200 * $size[0] / $size[1]); $thumbnail_height = 200; } // Build Thumbnail with GD 1.x.x, you can use the other described methods too $function_suffix = $gd_function_suffix[$filetype]; $function_to_read = "ImageCreateFrom".$function_suffix; $function_to_write = "Image".$function_suffix; // Read the source file $source_handle = $function_to_read ( $images_dir."/".$filename ); if($source_handle) { // Let's create an blank image for the thumbnail $destination_handle = ImageCreateTrueColor ( $thumbnail_width, $thumbnail_height ); // Now we resize it ImageCopyResized( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1] ); } // Let's save the thumbnail $function_to_write( $destination_handle, $images_dir."/tb_".$filename, 99 ); ImageDestroy($destination_handle ); // $result_final .= "<img src='".$images_dir. "/tb_".$filename."' /> File ".($counter+1)." Added<br />"; } } $counter++; } // Print Result echo <<<__HTML_END <html> <head> <title>Photos uploaded</title> </head> <body> $result_final </body> </html> __HTML_END; ?> this is my code im getting an error message Notice: Undefined offset: 20 in C:\wamp\www\examples\ideas\new2.php on line 33 Code: [Select] <?php echo "<table>\n"; //Move through a CSV file, and output an associative array for each line ini_set("auto_detect_line_endings", 1); $current_row = 1; $d=0; $handle = fopen("widget.csv", "r"); while ( ($data = fgetcsv($handle, 10000, ",") ) !== FALSE ) { $number_of_fields = count($data); echo "<thead>\n<tr>"; if ($current_row == 1) { //Header line /* for ($c=0; $c < $number_of_fields; $c++) */ { $header_array[$d] = $data[$d]; echo "<th>" . $data[$d] . "</th>"; } echo "</tr>\n</thead>\n\n<tbody>"; } else { //Data line for ($c=1; $c < $number_of_fields; $c++) echo "<tr>"; { $data_array[$c] = $data[$c]; /* echo "<td>" . $data[$c] . "</td>"; */ } echo "</tr>\n"; } $current_row++; } fclose($handle); echo "</tbody>\n</table>"; echo $number_of_fields; echo "<br />"; echo $current_row; ?> this is my csv file Quote A,Airlie Beach,Andergrove,Alexandra,Armstrong Beach,Alligator Creek,,,,,,,,,,,,,, B,Bucasia,Blacks Beach,Beaconsfield,Bakers Creek,Balberra,Bloomsbury,Breadalbane,Ball Bay,Belmunda,,,,,,,,,, C,Cannonvale,Calen,Crystal Brook,Cremorne,Chelona,Campwin Beach,Cape Hillsborough,Conway,,,,,,,,,,, D,Dows Creek,Dumbleton,Dolphin Heads,,,,,,,,,,,,,,,, E,Eimeo,Eton,Erakala,,,,,,,,,,,,,,,, F,Foulden,Foxdale,Flametree,Farleigh,Freshwater Point,,,,,,,,,,,,,, G,Glen Isla,Glenella,,,,,,,,,,,,,,, ,, H,Homebush,Hampden,,,,,,,,,,,,, ,,,, I,,,,,,,,,,,,,,, ,,,, J,Jubilee Pocket,,,,,,,,,,,,,, ,,,, K,Kinchant Dam,Kolijo,Koumala,Kuttabul,,,,,,,,,,, ,,,, L,Laguna Quays,,,,,,,,,,,,,, ,,,, M,McEwens Beach,Mackay,Mackay Harbour,Mandalay,Marian,Mia Mia,Middlemount,Midge Point,Mirani,Moranbah,Mount Charlton,Mount Jukes,Mount Julian,Mount Marlow,Mount Martin,Mount Ossa,Mount Pelion,Mount Pleasant,Mount Rooper N,Narpi,Nebo,Nindaroo,North Eton,,,,,,,,,,,,,,, O,Oakenden,Ooralea,,,,,,,,,,,,,,,,, P,Palmyra,Paget,Pindi Pindi,Pinevale,Pioneer Valley,Pleystowe,Preston,Proserpine,,,,,,,,,,, Q,,,,,,,,,,,,,,,,,,, R,Racecourse,Richmond,Riordanvale,Rosella,Rural View,,,,,,,,,,,,,, S,St Helens Beach,Sandiford,Sarina,Seaforth,Slade Point,Shoal Point,Shute Harbour,Shutehaven,Strathdickie,Sugarloaf,Sunnyside,,,,,,,, T,Te Kowai,The Leap,,,,,,,,,,,,,,,,, U,,,,,,,,,,,,,,,,,,, V,Victoria Plains,,,,,,,,,,,,,,,,,, W,Wagoora,Walkerston,Woodwark,,,,,,,,,,,,,,,, X,,,,,,,,,,,,,,,,,,, Y,Yalboroo,,,,,,,,,,,,,,,,,, Z,,,,,,,,,,,,,,,,,,, Could anyone please help little stuck on why its causing this error. Here is an example of the beginning of a rating system script: Code: [Select] // RATING SYSTEM - START if ((isset($array[0]) || isset($array[1])) && isset($_SESSION['user_id'])) { // check to see if user has already voted on given contribution $query = "SELECT * FROM votes WHERE con_id = '$array[2]' AND user_id = '$array[3]'"; $query_run = mysqli_query ($dbc, $query) or die (mysqli_error($dbc)); $num_rows = mysqli_num_rows ($query_run); $assoc = mysqli_fetch_assoc ($query_run); $rating = $assoc['rating']; // check to see if it's user's own contribution $query = "SELECT * FROM con WHERE con_id = '$array[2]'"; $query_run = mysqli_query ($dbc, $query) or die (mysqli_error ($dbc)); $assoc = mysqli_fetch_assoc ($query_run); $con_user_id = $assoc['user_id']; For every array variable I am getting the error message "Undefined Offset". Any ideas how to solve this one, I do not fully know yet what is common practice in these cases. The warnings also do not always happen, they usually happen, they happen in a specific moment when I use a drop down menu, to show table content. hello all, i am stuck with a problem and hoping someone can help me. i have got the following code to sort of work. the problem i am having is when i put e.g. index.php?page=test and there is no information with test under page in the sqlite db i get this message, Notice: Undefined offset: 0 in C:\xampp\htdocs\test\Frontend\left.php on line 8. as soon as i type index.php?page=test2 and i have test2 in the database the error is gone and shows the content heres the code Code: [Select] if (isset($_GET['page'])) { $page = $_GET['page']; // Display Page. $query = "SELECT body FROM content WHERE page = '$page' AND location = 'left' AND disabled = 'no' ORDER BY id"; $results = $base->arrayQuery($query, SQLITE_ASSOC); $arr = $results[0]; echo '<div id="left">'; echo '<p>' . $arr['body'] . '</p>'; echo '</div>'; } else { //Show Home Page $query = "SELECT body FROM content WHERE page = 'home' AND location = 'left' AND disabled = 'no' ORDER BY id"; $results = $base->arrayQuery($query, SQLITE_ASSOC); $arr = $results[0]; echo '<div id="left">'; echo '<p>' . $arr['body'] . '</p>'; echo '</div>'; } hope you understand what i am trying to say, thanks very much all. What I am trying to do is to associate a user (id) to a page they create, so if joe blogs is user 4, then the data base will show the page details, and add the id (from a user page). However, when I try the code to save data I get the following error messages:
Notice: Undefined offset: 4 in C:\xampp\htdocs\MyCMS\admin\index.php on line 98 I include the code to insert the page: <!-- Insert Page --> <?php if(isset($_POST['submitted']) == 1) { $header = stripslashes($_REQUEST['header']); $header = mysqli_real_escape_string($dbc, $header); $title = stripslashes($_REQUEST['title']); $title = mysqli_real_escape_string($dbc, $title); $body = stripslashes($_REQUEST['body']); $body = mysqli_real_escape_string($dbc, $body); $userid = stripslashes($_REQUEST['userid']); $userid = mysqli_real_escape_string($dbc, $userid); $q = "INSERT INTO `pages` (`userid`, `header`, `title`, `body`) VALUES ($_POST[$userid], '$header', '$title', '$body')"; $r = mysqli_query($dbc, $q) or die(mysqli_error($dbc)); if($r) { $message = '<p>Page was added.</p>'; } else { $message = '<p>Page could not be added due to: </p>'.mysqli_error($dbc); $message .= '<p>'.$q.'</p>'; } // end if inner } // end if outer ?> The form has - Page Header, Page Title, User, and boys. There is a working list of current users. It is these users (and new users) that I want to add to a 'Pages' database, which has the following fields: id, userid, header, title, body; and a 'User' database with the following fields: id, firstname, lastname, username, password, status. Any help to solve the issues will be appreciated. Thanks.
i get the error for this code: <?php $news = fopen("test.txt", "rb"); while (!feof($news) ) { $line = fgets($news); $parts = explode('=', $line); print $parts[0] . $parts[1]. "<BR>";//line 60!!! } fclose($news); ?> i know that this means that the array gets one argument instead of two but i do'nt know how to solve it... this code works fine in my localhost but not on the server |