PHP - Warning: Invalid Argument Supplied For Foreach()
I keep getting the following error.
Warning: Invalid argument supplied for foreach() in /home/content/46/8529846/html/wp-content/themes/super-light/functions.php on line 94 Warning: Cannot modify header information - headers already sent by (output started at /home/content/46/8529846/html/wp-content/themes/super-light/functions.php:94) in /home/content/46/8529846/html/wp-includes/pluggable.php on line 866 Code: [Select] <?php if ( ! isset( $content_width ) ) $content_width = 650; add_action( 'widgets_init', 'super_light_sidebars' ); function super_light_sidebars() { register_sidebar(array( 'name' => __( 'Sidebar Widget Area', 'super_light'), 'id' => 'sidebar-widget-area', 'description' => __( 'The sidebar widget area', 'super_light'), 'before_widget' => '<div class="widget">', 'after_widget' => '</div>', 'before_title' => '<h3>', 'after_title' => '</h3>', )); } register_nav_menus( array( 'primary' => __('Header Menu', 'super_light'), 'secondary' => __('Footer Menu', 'super_light') ) ); //Multi-level pages menu function super_light_page_menu() { if (is_page()) { $highlight = "page_item"; } else {$highlight = "menu-item current-menu-item"; } echo '<ul class="menu">'; wp_list_pages('sort_column=menu_order&title_li=&link_before=&link_after=&depth=3'); echo '</ul>'; } //Single-level pages menu function super_light_menu_flat() { if (is_page()) { $highlight = "page_item"; } else {$highlight = "menu-item current-menu-item"; } echo '<ul class="menu">'; wp_list_pages('sort_column=menu_order&title_li=&link_before=&link_after=&depth=1'); echo '</ul>'; } add_editor_style(); add_theme_support('automatic-feed-links'); add_theme_support('post-thumbnails'); set_post_thumbnail_size( 120, 120, true ); // Default size // Make theme available for translation // Translations can be filed in the /languages/ directory load_theme_textdomain('super_light', get_template_directory() . '/languages'); function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); $first_img = $matches [1] [0]; if(empty($first_img)){ //Defines a default image $first_img = "/images/default.jpg"; } return $first_img; } add_action('save_post','custom_field_add_tags'); function custom_field_add_tags($post_id) { $post = get_post($post_id); //get values of custom fields and put into array $tag1 = get_post_meta($post_id, 'tag_name1', true); $tag2 = get_post_meta($post_id, 'tag_name2', true); $tag3 = get_post_meta($post_id, 'tag_name3', true); $tag4 = get_post_meta($post_id, 'tag_name4', true); $tag5 = get_post_meta($post_id, 'tag_name5', true); $tag6 = get_post_meta($post_id, 'tag_name6', true); $tag7 = get_post_meta($post_id, 'tag_name7', true); $tag8 = get_post_meta($post_id, 'tag_name8', true); $tag9 = get_post_meta($post_id, 'tag_name9', true); $tags_to_add = array($tag1, $tag2, $tag3, $tag4, $tag5, $tag6, $tag7, $tag8, $tag9); //now check if tag does not already exist (if no - add tag from custom field) $add_tags = array(); foreach(get_the_terms($post_id, 'post_tag') as $term) if(!in_array($term->slug, $tags_to_add)) $add_tags[] = $term->slug; if(!empty($add_tags)) wp_add_post_tags($post_id, implode(',', $add_tags)); } ?> Similar TutorialsI am a total newbie at PHP and I have a wordpress plugin that works well but sometimes does not return any results to the query which I believe is causing this error: Warning: Invalid argument supplied for foreach() social-media-integrated-related-content-smirc/lib/smirclib.php on line 182 From what I am reading on other forums the problem is possibly that the foreach loop is empty since the array must have elements. The solution being to add a check above the foreach loop, to count the number of elements in the array, and if it is zero, skip the foreach loop. Is this correct? Here is the code....can someone please edit it so I can see an example of how it should be done? Again total PHP newbie so please be clear if possible. Thanks so much!!! Code: [Select] <? /** * Object for getting, parsing, and prepping external related content * * @author Husani S. Oakley * @version 1.0 */ class SMIRC{ var $total_results; var $page_title; var $default_header_text = "Blog discussions:"; var $search_urls = array( "google_blogsearch_norss" => "http://blogsearch.google.com/blogsearch?client=news&um=1&hl=en&scoring=d&q=SEARCHTERM&ie=utf-8", "google_blogsearch" => "http://blogsearch.google.com/blogsearch_feeds?client=news&um=1&hl=en&scoring=d&q=SEARCHTERM&ie=utf-8&num=NUMRESULTS&output=rss", "twitter_search" => "http://search.twitter.com/search.atom?q=SEARCHTERM&rpp=NUMRESULTS" ); /** * constructor */ function SMIRC($page_title, $title_separators, $required_keyword, $data_sources, $header_text, $animation=false){ $this->page_title = $page_title; $this->title_separators = $title_separators; $this->required_keyword = $required_keyword; $this->data_sources = $data_sources; if($header_text == ""){ $this->header_text = $this->default_header_text; } else { $this->header_text = $header_text; } $this->animation = $animation; } /** * main work method. create url, get data, parse, prep and return xhtml */ function getContent(){ //don't bother doing anything if we don't have any data sources if(!is_array($this->data_sources)){ return false; } //if we have delimiter characters, use them to split up the title $searchterm = $this->_getSearchTerm(); //start assembling data foreach($this->data_sources as $source_array){ //prep url $data_source = str_replace("SEARCHTERM", $searchterm, $this->search_urls[$source_array[0]]); $data_source = str_replace("NUMRESULTS", $source_array[1], $data_source); //get data, put into array $rss_data_array[$source_array[0]]['results'] = $this->_getResults($data_source, split("\n", $source_array[2])); $rss_data_array[$source_array[0]]['header'] = $source_array[3]; } //create and return xhtml for all sources $xhtml = $this->_createXHTML($rss_data_array, $this->header_text); return $xhtml; } /** * create and return all xhtml */ function _createXHTML($rss_array, $header_text){ foreach($rss_array as $data_source => $results_and_header){ //run function to get xhtml from rss object -- name of function depends on data source. $lists_xhtml .= $this->$data_source($results_and_header['results'], $results_and_header['header']); } if($lists_xhtml == ""){ //no results = no xhtml return false; } else { $all_xhtml = '<div class="smirc_wrapper">'; $all_xhtml .= '<h2 class="collapsed">'.$this->_getHeaderXHTML().'</h2>'; $all_xhtml .= '<ul class="smirc_ul">'; //add results to overall xhtml $all_xhtml .= $lists_xhtml; $all_xhtml .= "</ul>"; $all_xhtml .= '</div>'; return $all_xhtml; } } /** * GOOGLE BLOGSEARCH: iterate through rss object and create standards-compliant xhtml for the resultset, while ignoring items in exclude list */ function google_blogsearch($rss_items, $result_header){ $list_xhtml = ""; if(count($rss_items) >= 1){ $list_xhtml = ""; foreach($rss_items as $item){ $fixed_item = $this->_parseItem($item); $list_xhtml .= '<div class="summary">'.strip_tags($fixed_item['summary']).'</div></li>'; } } return $list_xhtml; } /** * TWITTER SEARCH: iterate through rss object and create standards-compliant xhtml for the resultset * search.twitter.com doesn't seem to have results limits, so we'll have to do that manually. */ function twitter_search($rss_items, $result_header){ $list_xhtml = ""; if(count($rss_items) >= 1){ $list_xhtml = ""; foreach($rss_items as $item){ $fixed_item = $this->_parseItem($item); $list_xhtml .= '<li>'.$fixed_item['atom_content'].' by <a href="'.$fixed_item['author_uri'].'" rel="nofollow" target="_blank">'.$fixed_item['author_name'].'</a></li>'; } } return $list_xhtml; } /** * use title separators (if any) to prepare search term(s) */ function _getSearchTerm(){ if(is_array($this->title_separators)){ //make this easy -- replace all matches to items in separators array with a common character $title = $this->page_title; foreach($this->title_separators as $delimiter){ $title = str_replace($delimiter, "###", $title); } //split by this common character $arr = split("###", $title); //iterate, trim, add to array foreach($arr as $phrase){ $searchterms[] = trim($phrase); } $searchterms[] = $this->required_keyword; } else { //no separators. search terms are title and required keyword if any $searchterms[] = $this->page_title; $searchterms[] = $this->required_keyword; } //iterate through searchterms and add quotation marks / urlencode as needed $str = a; foreach($searchterms as $term){ $str .= '' . urlencode($term) . ''; } return $str; } /** * using the exclude list (if set) and MagpieRSS, return an array of data sources and results */ function _getResults($data_source, $exclude_list){ $rss = fetch_rss($data_source); //set total results $this->_setTotalResults($rss); $results = $rss->items; //is there an exclude list? if(is_array($exclude_list)){ //yes. iterate and remove foreach($exclude_list as $exclude_me){ $matches = $this->array_search_recursive($exclude_me, $results); unset($results[$matches[0]]); } } return $results; } /** * unfortunately-ghetto way to remove google's BOLDING of matching wordds */ function _parseItem($arr){ $newarr; if(!is_array($arr)){ return $arr; } foreach($arr as $key => $value){ $newval = str_replace("<b>", "", $value); $newval = str_replace("</b>", "", $newval); $newarr[$key] = $newval; } return $newarr; } /** * recursively search a multidimensional array */ function array_search_recursive($needle, $haystack, $path=array()){ foreach($haystack as $id => $val){ $path2 = $path; $path2[] = $id; if(eregi($needle, $val)){ return $path2; } else if(is_array($val)){ if($ret = $this->array_search_recursive($needle, $val, $path2)){ return $ret; } } return false; } } /** * add to total results count */ function _setTotalResults($rss){ if($rss->channel['opensearch']['totalresults']){ $this->total_results = $this->total_results + $rss->channel['opensearch']['totalresults']; } } /** * create header text / link */ function _getHeaderXHTML(){ //create link $link = str_replace("SEARCHTERM", $this->_getSearchTerm(), $this->search_urls['google_blogsearch_norss']); return " "; } } ?> Hi , can somebody help me with this warning?
Warning: Invalid argument supplied for foreach() in /home/wwwdesig/public_html/mailer.php on line 12
It´s just a simple php mailer
Here is the php code:
<?php
if(isset($_POST['submit'])) { I have the following code: if ( !empty($_GET['quantity']) ) { foreach ( $_GET['quantity'] as $order_code => $quantity ) { // line 13 $Cart->setItemQuantity($order_code, $quantity); } } and I'm getting the following error: Quote Warning: Invalid argument supplied for foreach() in shopping-cart/cart_action.php on line 13 $_GET['quantity']; has a value of '1' The code is working perfectly fine on localhost, but throws me that warning on my webserver(both have error reporting set to E_ALL) any help is greatly appreciated. Thanks. This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=355998.0 When I call load_new_flows.php with Ajax to update the content, I got "Warning: Invalid argument supplied for foreach() in load_new_flows.php on line 4", but with the load_flows.php everything is ok. index.php Code: [Select] <?php error_reporting(0); include 'includes/db.php'; include 'includes/functions.php'; include 'includes/tolink.php'; include 'includes/time_stamp.php'; include 'includes/facebook/fbmain.php'; $brainflow = new brainflow(); // TEST // ------------------------------------ $level = 1; //overflowing = 3, flowing = 2, fresh = 1 // ------------------------------------ $flowsarray = $brainflow -> get_flows($level); $newflowsarray = $brainflow -> get_new_flows($level); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type = "text/javascript" src = "js/brainflow.js"></script> <title>test</title> </head> <body> <br /><br /> <div id="new"></div> <br /><br /> <div id ="flows"> <?php // LOAD FLOWS // ------------------------------------ include 'load_flows.php'; // ------------------------------------ ?> </div> </body> </html> load_new_flows.php Code: [Select] <?php foreach($newflowsarray as $data) { $new_flow_id = $data['flow_id']; $new_owner_id = $data['user_id_fk']; $new_owner_facebook_id = $data['facebook_id']; $new_flow = tolink(htmlentities($data['flow'])); $new_time = $data['time']; $new_owner_name = $data['name']; //$commentsarray = $brainflow -> get_comments($flow_id); ?> <div class="flow" id="<?php echo $new_flow_id; ?>"> <img src="images/pictures/<?php echo $new_owner_facebook_id; ?>.png"> <?php echo $new_owner_name; ?> <?php echo $new_flow; ?> <?php echo time_stamp($new_time); ?> </div> <?php } ?> load_flows.php Code: [Select] <?php foreach($flowsarray as $data) { $flow_id = $data['flow_id']; $owner_id = $data['user_id_fk']; $owner_facebook_id = $data['facebook_id']; $flow = tolink(htmlentities($data['flow'])); $time = $data['time']; $owner_name = $data['name']; //$commentsarray = $brainflow -> get_comments($flow_id); ?> <div class="flow" id="<?php echo $flow_id; ?>"> <img src="images/pictures/<?php echo $owner_facebook_id; ?>.png"> <?php echo $owner_name; ?> <?php echo $flow; ?> <?php echo time_stamp($time); ?> </div> <?php } ?> includes/functions.php Code: [Select] <?php class brainflow { // GET FLOWS public function get_flows($level) { $query = mysql_query("SELECT F.flow_id, F.user_id_fk, F.flow, F.time, U.name, U.facebook_id FROM flows F, users U WHERE F.user_id_fk = U.user_id AND F.level = '$level' ORDER BY F.flow_id DESC ") or die(mysql_error()); while($row = mysql_fetch_array($query)) $data[] = $row; return $data; } // GET NEW FLOWS public function get_new_flows($level) { $last_flow_id = $_POST['id']; $query = mysql_query("SELECT F.flow_id, F.user_id_fk, F.flow, F.time, U.name, U.facebook_id FROM flows F, users U WHERE F.user_id_fk = U.user_id AND F.flow_id > '$last_flow_id' AND F.level = '$level' ORDER BY F.flow_id DESC ") or die(mysql_error()); while($row = mysql_fetch_array($query)) $data1[] = $row; return $data; } } js Code: [Select] $(document).ready(function() { $("#new").click(function() { var id = $(".flow:first").attr("id"); datastring = 'id=' + id; $.ajax({ type: "POST", url: "load_new_flows.php", data: datastring, cache: false, success: function(html){ $("#flows").prepend(html); } }); }); }); I am having problem with my edit.php page, Keep on getting Invalid argument supplied for foreach() My edit.php is suppose to get the drop down list from the first page. and replace the string [Replace] with whats in the list box But it has to Use the first thing in the list box 2 times, and ect. Code: [Select] <form method="post" action="edit.php" > <select name="drop1"> <?php echo $dropdownOptions; ?> </select> <input type="submit" value="drop1" /> </form> Edit.php Code: [Select] <? $file = file_get_contents('myfile.txt'); foreach($_POST['drop1'] as $replace) { $file = preg_replace('#\[Replace\]#', $replace, $file, 2); } ?> hello, whats wrong with this loop ? Code: [Select] <?PHP require_once("../includes/initialize.php"); $pName == "adminHome"; $currentPage = Pages::find_by_pageName($pName); $topNavs = NavL1::find_all(); ?> <div id="navWrapper"> <div id="ddtabs3" class="solidblockmenu"> <ul> <?PHP foreach ($topNavs as $topNav){ $L1nav_id = $topNav->id; $L1navPages_id = $topNav->pages_id; $L1navTitle = $topNav->title; foreach ($currentPage as $currentPages){ $L1page_id = $currentPages->id; $L1pageName = $currentPages->pageName; } if($L1navPages_id == $L1page_id){ $L1nav_selected='class="selected"'; }else{ $L1nav_selected=''; } echo '<li><a '.$L1nav_selected.' href="'.$L1pageName.'.php" id="'.$L1nav_id.'">'.$L1navTitle.'</a></li>'; } ?> </ul> </div> </div> ?> i get this error for each of the tabs Code: [Select] Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/djsonrotation/admin/templates/template1/includes/topCont.php on line 21 Hello people, I'm working with an autocomplete script, which is actually working. I've got 2 problems though, the first problem should be very easy but I'm really noobish. I don't know how to fill my array correctly, right now it seems that I'm filling my array with just 1 result, instead of all results. The second problem is, although it's actually working, an error log is created everytime I use the autocomplete box. Error: [30-Jul-2010 18:19:29] PHP Warning: Invalid argument supplied for foreach() in /home/admin/public_html/adminpanel/autocomplete/search-artistnames.php on line 79 I really could use some help here, I'm lost atm. I hope you guys have the answer for me. The code: <?php $link = mysql_connect('localhost', '****', '****'); if (!$link) { die('Could not connect: ' . mysql_error()); } if (!mysql_select_db(' ****')) { exit; } $text = strtolower($_GET["term"]); if (!$text) return; $sql = "SELECT artistID, artistname FROM artists WHERE artistname LIKE '%".mysql_real_escape_string($text)."%' LIMIT 5"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $items = array($row['artistname'] => $row['artistID']); } function array_to_json( $array ){ if( !is_array( $array ) ){ return false; } $associative = count( array_diff( array_keys($array), array_keys( array_keys( $array )) )); if( $associative ){ $construct = array(); foreach( $array as $key => $value ){ // We first copy each key/value pair into a staging array, // formatting each key and value properly as we go. // Format the key: if( is_numeric($key) ){ $key = "key_$key"; } $key = "\"".addslashes($key)."\""; // Format the value: if( is_array( $value )){ $value = array_to_json( $value ); } else if( !is_numeric( $value ) || is_string( $value ) ){ $value = "\"".addslashes($value)."\""; } // Add to staging array: $construct[] = "$key: $value"; } // Then we collapse the staging array into the JSON form: $result = "{ " . implode( ", ", $construct ) . " }"; } else { // If the array is a vector (not associative): $construct = array(); foreach( $array as $value ){ // Format the value: if( is_array( $value )){ $value = array_to_json( $value ); } else if( !is_numeric( $value ) || is_string( $value ) ){ $value = "'".addslashes($value)."'"; } // Add to staging array: $construct[] = $value; } // Then we collapse the staging array into the JSON form: $result = "[ " . implode( ", ", $construct ) . " ]"; } return $result; } $result = array(); foreach ($items as $key=>$value) { if (strpos(strtolower($key), $text) !== false) { array_push($result, array("id"=>$value, "label"=>$key, "value" => strip_tags($key))); } if (count($result) > 11) break; } echo array_to_json($result); mysql_close($link); ?> I am simply trying to display the last 8 images from a mysql database and i am getting this error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/aretheyh/public_html/nealeweb.com/gnew2/recent.php on line 8 Can somebody please tell me what i am doing wrong. Code: [Select] <?php $i = 1; echo '<table border="0" cellpadding="0" cellspacing="0"> <tr>'; include("config.inc.php"); $result = mysql_query("SELECT * FROM gallery_photos ORDER BY id DESC LIMIT 8"); while($row = mysql_fetch_assoc($result)) { // Start of the loop $img = $row['".$images_dir."/tb_']; echo "<td><img src=$img></td>"; if ($i == 4) { echo '</tr><tr>'; } $i++; } echo '</tr></table>'; so I have an array with a bunch of photos, and I'm trying to create a thumbnail of each to display on a page with a link to the full sized image but I'm getting the error in the subject title... if I just display the images in the array without trying to resize them it works fine... can anyone clue me into why this isn't working please. echo ("<a href='" . $img['file'] . "'>"); $new_width = (floor($img['size'][0] * ".25")); $new_height = (floor($img['size'][1] * ".25")); $tmp_img = imagecreatetruecolor($new_width, $new_height); imagecopyresized($tmp_img, $img['file'], 0, 0, 0, 0, $new_width, $new_height, $img['size'][0], $img['size'][1]); echo ("<img src='" . $tmp_img . " . $img['size'][3] , "' alt=''><br>\n"); echo basename($img['file']); echo "</a><br>\n"; Hi guys, I'm doing a website for the condo and I'm having troubles with the new year party registration form. I think it's got something to do with my file handling. When I run it on my wamp server, it works fine. But when I upload it onto the internet it gives me a whole bunch of warnings: Warning: fopen(newYearParty.txt) [function.fopen]: failed to open stream: Permission denied in /www/zymichost.com/i/n/d/inderasubangcondo/htdocs/newYrRegTq.php on line 18 Warning: fgets(): supplied argument is not a valid stream resource in /www/zymichost.com/i/n/d/inderasubangcondo/htdocs/newYrRegTq.php on line 19 Warning: fgets(): supplied argument is not a valid stream resource in /www/zymichost.com/i/n/d/inderasubangcondo/htdocs/newYrRegTq.php on line 20 Heres my code: <?php $nam = $_POST["nam"]; $block = $_POST["block"]; $floor = $_POST["floor"]; $house = $_POST["house"]; $adults = $_POST["adults"]; $children = $_POST["children"]; $guests = $_POST["guests"]; $nam = $_POST["nam"]; global $fn, $ft; //set id and update total numbers $fn = fopen("newYearParty.txt","a+"); $line1 = fgets($fn); $arr1 = explode(": ", $line1); //adults $line2 = fgets($fn); $arr2 = explode(": ", $line2); //children $line3 = fgets($fn); $arr3 = explode(": ", $line3); //guests $line4 = fgets($fn); $arr4 = explode(": ", $line4); //total $line4 = fgets($fn); //blank line $numAdults = $arr1[1]+$adults; $numChildren = $arr2[1]+$children; $numGuests = $arr3[1]+$guests; $numTotal = $numAdults+$numChildren+$numGuests; $id = "nothing"; while(!feof($fn)) { $line = fgets($fn); //id $arr = explode(": ", $line); $id = $arr[1] + 1; //get latest id and add 1 to it for($i=0; $i<6; $i++) { $line = fgets($fn); } } fclose($fn); if($id == "nothing") { $id = "0"; } //end of set id //write to file $line0 = "\r\nId: ".$id."\r\n"; $line1 = "Name: ".$nam."\r\n"; $line2 = "Unit: ".$block."-".$floor."-".$house."\r\n"; $line3 = "Adults: ".$adults."\r\n"; $line4 = "Children: ".$children."\r\n"; $line5 = "Guests: ".$guests."\r\n"; $fn = fopen("newYearParty.txt","a+"); fwrite($fn, $line0); fwrite($fn, $line1); fwrite($fn, $line2); fwrite($fn, $line3); fwrite($fn, $line4); fwrite($fn, $line5); fclose($fn); //end of write to file //write new numbers to file $ft = fopen("newYearPartyTemp.txt","a+"); $lineA = "Adults: ".$numAdults."\r\n"; $lineC = "Children: ".$numChildren."\r\n"; $lineG = "Guests: ".$numGuests."\r\n"; $lineT = "Total: ".$numTotal."\r\n\r\n"; fwrite($ft, $lineA); fwrite($ft, $lineC); fwrite($ft, $lineG); fwrite($ft, $lineT); $fn = fopen("newYearParty.txt","a+"); for($i=0; $i<5; $i++) { $line = fgets($fn); } while(!feof($fn)) { $line = fgets($fn); fwrite($ft, $line); } fclose($fn); fclose($ft); unlink("newYearParty.txt"); //delete newYearParty.txt rename("newYearPartyTemp.txt","newYearParty.txt"); //rename newYearPartyTemp.txt to newYearParty.txt //end of write new numbers to file ?> Any ideas on how to fix this up? Thanks a lot in advance. My new host (Siteground) cloned and moved my html/php site (built by the previous owner) from Heart Internet server. All of the site works except for the sidebar, I get these 2 errors. Anyone shed any light on these at all?
Warning: readdir(): supplied argument is not a valid Directory resource in /home/customer/www/dunster.org.uk/public_html/include/toolbox.php on line 97
Warning: opendir(/home/sites/dunster.org.uk/public_html//local_information) [function.opendir]: failed to open dir: No such file or directory in /home/customer/www/dunster.org.uk/public_html/include/toolbox.php on line 86 Hi, I am having problem with mysql and php.... when i test the database on my local host it didt produce any error but when i put it on my web host it gave me error messages... "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource" Please help me as i am new to php. Quote <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" href="http://www.hingloong.com/pricesearch/style.css" /> <title>Price Search Query</title> </head> <body> <form method=GET action="search.php"> <div id=container> <select name=general> <option value = all>Select</option> <option value = laptop>Laptop</option> <option value = mobile>Mobile</option> <option value = games>Games</option> <option value = camera>Camera</option> </select> <label><b>Brand:</b></label> <input type=text name=brand> <label><b>Model:</b></label> <input type=text name=model> <input type=submit name=search value=Search> </form> <br><br> <input type=button name=gamelist value=View Games onclick="location.href='gamelist.php'"> <input type=button name=mobilelist value=View Mobile onclick="location.href='mobilelist.php'"> <input type=button name=cameralist value=View Cameras onclick="location.href='cameralist.php'"> <input type=button name=laptoplist value=View Laptops onclick="location.href='laptoplist.php'"> </div> </body> </html> <?php include ("connect.php"); $general = $_GET['general']; $brand = $_GET['brand']; $model = $_GET['model']; if($general == 'mobile') { echo "<br>"; echo "<h3>Mobile Phone Prices</h3>"; echo "<div id=container>"; echo "<table>"; echo "<tr>"; echo "<td class=head>Phone Brand</td>"; echo "<td class=head>Phone Model</td>"; echo "<td class=head>Phone Loan</td>"; echo "<td class=head>Phone Buy</td>"; echo "<td class=head>Phone Sell</td>"; echo "<td class=head>Phone Rrp</td>"; echo "</tr>"; $query = "select * from mobilephones where phone_brand LIKE ('$brand%') AND phone_model LIKE ('$model%') "; $temp = mysql_query($query) or die(mysql_error()); } while ($row = mysql_fetch_array($temp)) { echo "<tr>"; echo "<td>" .$row['phone_brand']. "</td>"; echo "<td>" .$row['phone_model']. "</td>"; echo "<td>" .$row['phone_loan']. "</td>"; echo "<td>" .$row['phone_buy']. "</td>"; echo "<td>" .$row['phone_sell']. "</td>"; echo "<td>" .$row['phone_rrp']. "</td>"; } echo "</table>"; echo "</div>"; ?> Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 14. <?PHP require_once("dbcheck.php"); require_once("check.php"); $Username=$_COOKIE['Username']; $Password=$_COOKIE['Password']; $Nickname=$_COOKIE['Nickname']; $Username=mysql_real_escape_string($Username); $Password=mysql_real_escape_string($Password); date_default_timezone_set('Asia/Calcutta'); $action = $_GET['do']; $Result=mysql_query("SELECT * FROM Checks WHERE UserName='$Username'"); $Rowexist=mysql_num_rows($Result); if($Rowexist!=0){ while($Rows=mysql_fetch_array($Result)) { $Serial = $Rows['Serial']; $Banned = $Rows['Banned']; $IP = $Rows['IP']; $Used = $Rows['Used']; $First = $Rows['First']; $Duration = $Rows['Duration']; $Total = $Rows['Total']; $Time = $Rows['Time']; } if($action=="" || $action=="Banlist"){ mysql_query("UPDATE Checks SET NickName='$Nickname' WHERE UserName='$Username'"); ?> Hi, first post, and yes it is a question. I am stuck, and not by choice, this error has given me more headaches than I care to admit. I have a script that I am attempting here, that is very simple for now, all I want to show is the Added_By field to show it is accessing the database correctly and the right row/line all together. The page to test this at is he http://kaboomlabs.com/PDI/@dm!n/viewncmr.php?id=2 The Error is this: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/pawz/public_html/kaboomlabs.com/PDI/@dm!n/viewncmr.php on line 18 This is row 18: $row = mysql_fetch_array($data); Now I know this is not a secure form yet, I am working on getting the basic functions down then I'll secure it, so please let me worry about that when the time comes. Here is the script, can anyone see a blatant issue or not? Thanks in advance. Code: [Select] <?php require_once('../connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Grab the profile data from the database if (!isset($_GET['id'])) { $query = "SELECT * FROM ncmr WHERE id = '" . $_SESSION['id'] . "'"; } else { $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'"; $data = mysqli_query($dbc, $query); } if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysql_fetch_array($data); echo '<fieldset>'; if (!empty($row['Added_By'])) { echo '<div id ="added"><label>Added By:</label>' . $row['Added_By'] . '</div></fieldset>'; } } // End of check for a single row of user results else { echo '<p class="error">There was a problem accessing your profile.</p>'; } mysqli_close($dbc); ?> some please help - basically have a simple password change php page $sql="UPDATE t_members SET Password = '$New_Password' WHERE Username = '$My_Username' AND Password = '$Old_Password'"; echo $sql; $result=mysql_query($sql) or die(mysql_error()); $firstcount = mysql_num_rows($result); and i get this annoying error Warning: mysql_num_rows(): supplied argument is not a valid the sql statement works as i see it updating the database correctly In the following code, at the mysql query immediately following the <!--end accordianButton div-->, Some of the rows will echo out the content, while some of the rows will throw the Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in... error. Any idea why? Go here to see what I mean: http://www.chalmerscommunitychurch.com/P2P_archives.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=utf-8" /> <title>Pastor to People Blog Archives</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"> </script> <script type="text/javascript" src="js/javascript.js"> </script> <style> .accordionButton { width: 100%; height:30px; float: left; background: url(../images/button.png); border-bottom: 1px solid #FFFFFF; cursor: pointer; } .accordionContent { width: 100%; float: left; display: none; } </style> </head> <body> <?php require("include.php"); $con = mysql_connect("$db_host","$db_username","$db_pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("chalmers_db", $con); $result = mysql_query("SELECT title, date FROM blog"); while($row = mysql_fetch_array($result)) { $title=$row['title']; $sqldate=$row['date']; $date=date('m-d-Y',strtotime($sqldate)); ?> <!--start accordionButton div--> <div class="accordionButton"><?php echo $title;?>, <?php echo $date;?> </div> <!--end accordianButton div--> <?php $query = mysql_query("SELECT content FROM blog WHERE title = '".$title."' ORDER BY date DESC"); while ($row = mysql_fetch_array($query)){ $content = $row['content']; ?> <!--start accordionContent div--> <div class="accordionContent" align="justify"> <?php echo $content;?> </div> <!--end accordionContent div--> <?php } ?> <?php } ?> <p><p><p><p><a href="http://www.chalmerscommunitychurch.com"><h3>Back to Chalmers Community Church</h3></a> </body> </html> Hi, I am having an issue with a piece of code. I am getting the following error, any ideas please? Quote Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ... Code: [Select] <?php include "scripts/connect.php"; $last = $_GET['ref']; // This will be the ID of the page echo "the ref number is $last"; $query = mysql_query("SELECT * FROM news WHERE `ref` = '$last'"); if(mysql_num_rows($query)==0){ die("Something went wrong, contact Administrator!"); }else{ while($info = mysql_fetch_array($query)){ $title = $info ['title']; echo "<p><a href=\"..news.php\" target=\"_blank\">$title >></a></p>"; } } ?> |