PHP - Invalid Argument Supplied For Foreach()
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); } ?> Similar Tutorialshello, 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 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); } }); }); }); 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 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. 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)); } ?> I 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'])) { This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=355998.0 I'm trying to list all the tables in my database. I got this code pretty much "word" for word from the example at php.net, but I get: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\wamp\www\test\test-in.php on line 67 <?php $db= $_POST['db']; $sql= "SHOW TABLES FROM $db"; $result=mysql_query($sql); while ($tblarray = mysql_fetch_row($result)){ ?><a href="?tablename=<?php echo $tblarray[0];?>"><?php echo $tblarray[0];?></a><?php } ?> I have searched for this topic here but have not found reference to it. I am receiving the following: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a4542527/public_html/index.php on line 8 The scripting for this is basic at this point (I am building something in steps and this is just a test section: The script will call data from the table and display said data.) The following is the code (two, separate files located on my server)- I am hoping that someone may see something that I am missing. connection.php <?php $dbhost = 'mysql7.000webhost.com'; $dbuser = 'a4542527_root'; $dbpass = '**********'; $db = 'a4542527_test1'; $conn = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($db); ?> index.php <?php include 'connection.php'; $query = "SELECT * FROM people"; $result = "mysql_query($query)"; while ($person = mysql_fetch_array($result)){ echo $person ['name']; echo $person ['descrip']; } ?> Thank-you for any help, suggestions or a point in the right direction. ~Matty Hi everyone!! I finish to do my second populating drop down list. it's not realy the display I was looking but for now it will be good. but when I click on my serach button I receive this erro. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\scale24-25\search-keyword.php on line 112 this is what line 112 is in the search file. //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ <-------------- line 112 here's the code of my form... <?php include_once("connection.php"); ////////////////////////////// ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>1/24 - 1/25 scale model database</title> <SCRIPT language=JavaScript> function reload(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='search-db-foreach.php?cat=' + val ; } </script> </head> <body > <img src="http://www.scale24-25.com/images/banners/banner.jpg" alt="banner" width="997" height="213" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="poly" coords="0,100,85,102,92,55,108,50,326,51,323,7,3,3" href="http://www.hobby-shop.qc.ca" alt="hobby-shop" /> <area shape="poly" coords="672,57,891,53,887,4,995,4,985,108,673,102" href="http://www.hobby-shop.qc.ca" alt="hobby-shop" /> <area shape="poly" coords="326,13,330,53,98,54,90,92,670,99,668,54,889,51,886,5" href="http://www.scale-auto-style.com" alt="" /> </map> <?php if (isset($_POST['todo']) && $_POST['todo'] == "search") { $todo=$_POST['todo']; $manufacturer_reel=$_POST['manufacturer_reel']; $query="select * from kit where "; ////////// Including manufacturer_reel field search //// if(strlen($manufacturer_reel) > 0 ){ $query.= " manufacturer_reel='$manufacturer_reel' and "; } //// End of class field search /////////// $query=substr($query,0,(strLen($query)-4)); echo $query; echo "<br><br>"; $nt=mysql_query($query); echo mysql_error(); // End if form submitted }else{ echo "<form method=post action='search-keyword.php?go'><input type=hidden name=todo value=search>"; ?> <table width="960" border="0"> <tr> <td colspan="3"><table width="100%" border="0"> <tr> </tr> <tr> <td><div align="right"></div></td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td><div align="right">Echelle du modele</div></td> <td align="center"> <?php // strat of drop down /// $q=mysql_query("SELECT DISTINCT scale FROM kit ORDER BY scale"); echo '<select name="scale"><option value="scale">Please Choose an Option</option>'; while($row = mysql_fetch_array($q)) { $thing = $row['scale']; echo '<option>'.$thing.'</option>'; } echo "</select>"; echo " <br> \n"; echo " <br> \n"; ?></td> <td><div align="left">Scale of model</div></td> </tr> <tr> <td> </td> <td> </td> <td><div align="right"></div></td> </tr> <tr> <td><div align="right">Nom du manufacturier automobile</div></td> <td align="center"><?php // strat of drop down /// /* If register_global is off in your server then after reloading of the page to get the value of cat from query string we have to take special care. @$cat=$_GET['cat']; // Use this line or below line if register_global is off if(strlen($cat) > 0 and !is_numeric($cat)){ // to check if $cat is numeric data or not. echo "Data Error"; exit; } */ @$cat=$HTTP_GET_VARS['cat']; // Use this line or above line if register_global is off ///////// Getting the data from Mysql table for first list box////////// $quer2=mysql_query("SELECT DISTINCT manufacturer_reel,manufacturer_reel_id FROM kit order by manufacturer_reel"); ///////////// End of query for first list box//////////// /////// for second drop down list we will check if manufacturer_reel is selected else we will display all the car_model///// if(isset($cat) and strlen($cat) > 0){ $quer=mysql_query("SELECT DISTINCT car_model FROM kit where manufacturer_reel_id=$cat order by car_model"); }else{$quer=mysql_query("SELECT DISTINCT car_model FROM kit order by car_model"); } ////////// end of query for second car_model drop down list box /////////////////////////// ////////// Starting of first drop downlist ///////// echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['manufacturer_reel_id']==@$cat){echo "<option selected value='$noticia2[manufacturer_reel_id]'>$noticia2[manufacturer_reel]</option>"."<BR>";} else{echo "<option value='$noticia2[manufacturer_reel_id]'>$noticia2[manufacturer_reel]</option>";} } echo "</select>"; ////////////////// This will end the first drop down list /////////// ////////// Starting of second drop downlist ///////// echo "<select name='subcat'><option value=''>Select one</option>"; while($noticia = mysql_fetch_array($quer)) { echo "<option value='$noticia[car_model]'>$noticia[car_model]</option>"; } echo "</select>"; // end of drop down /// echo " <br> \n"; echo " <br> \n"; // end of drop down /// ?></td> <td><div align="left">Name Of vehicule manufacturer</div></td> </tr> <tr> <td> </td> <td> </td> <td><div align="right"></div></td> </tr> <tr> <td><div align="right">Nom du manufacturier de modele reduit</div></td> <td align="center"><?php // start of drop down /// $q=mysql_query("SELECT DISTINCT manufacturer_kit FROM kit ORDER BY manufacturer_kit"); echo '<select name="manufacturer_kit"><option value="kit manufacturer">Please Choose an Option</option>'; while($row = mysql_fetch_array($q)) { $thing = $row['manufacturer_kit']; echo '<option>'.$thing.'</option>'; } echo "</select>"; // end of drop down /// echo " <br> \n"; echo " <br> \n"; ?></td> <td><div align="left">Name Of kit manufacturer</div></td> </tr> <tr> <td><div align="right"></div></td> <td> </td> <td> </td> </tr> <tr> <td><div align="right">Annee de fabrication du Vehicule</div></td> <td align="center"><?php // strat of drop down /// $q=mysql_query("SELECT DISTINCT year_prod_reel FROM kit ORDER BY year_prod_reel"); echo '<select name="year_prod_reel"><option value="vehicules year manufactured">Please Choose an Option</option>'; while($row = mysql_fetch_array($q)) { $thing = $row['year_prod_reel']; echo '<option>'.$thing.'</option>'; } echo "</select>"; // end of drop down /// echo " <br> \n"; echo " <br> \n"; ?></td> <td><div align="left">Year of production of the vehicule</div></td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td align="center"> </td> <td> </td> </tr> <tr> <td><div align="right"><strong></strong></div></td> <td align="center"> <?php echo " <br><input type=submit value=Search name='name' action='search-keyword.php?go' > </form> "; } ?> <td><div align="left"><strong></strong></div></td> </table> </body> </html> and this the search file <?php include_once("connection.php"); ////////////////////////////// ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>(Type a title for your page here)</title> </head> <body > <p align="center"><img src="http://www.scale24-25.com/catalog/images/banners/banner.jpg" alt="banner" width="997" height="213" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="poly" coords="0,100,85,102,92,55,108,50,326,51,323,7,3,3" href="http://www.hobby-shop.qc.ca" alt="hobby-shop" /> <area shape="poly" coords="672,57,891,53,887,4,995,4,985,108,673,102" href="http://www.hobby-shop.qc.ca" alt="hobby-shop" /> <area shape="poly" coords="326,13,330,53,98,54,90,92,670,99,668,54,889,51,886,5" href="http://www.scale-auto-style.com" alt="" /> </map></p> <table width="920" border="0"> <tr> <td width="359"><p class="style5">You will find some TBC. TBC is for "To Be Confirmed". If somebody know the missing information ( TBC ) it will be appreciate to send it to me at this mail: <a href="mailto:info@hobby-shop.qc.ca">info@hobby-shop.qc.ca</a> <br /> <br /> thanks in advance for your help</p> </td> <td width="161"><div align="center"><a href="search-db-foreach.php"><img src="catalog/images/design_web/othersearch.jpg" border="0" alt="search" width="150" height="96"></a></div></td> <td width="386"> <div align="right"> <p>This logo <img src= 'http://www.scale24-25.com/images/PDF_logo.gif' width='50' height='50'/> mean that you can download a PDF file. To read it you need minimum Acrobat reader and you can download it <a href="http://get.adobe.com/reader/">here</a></p> <p>Some link will return a TBC. Sorry for any inconveniant. as soon as we will receive or do the PDF it will be updated.</p> </div></td> </tr> </table> <br> <?php if (isset($_POST['todo']) && $_POST['todo'] == "search") { $todo=$_POST['todo']; $name=$_POST['cat']; $name1=$_POST['manufacturer_kit']; $name2=$_POST['year_prod_reel']; $name3=$_POST['scale']; $name11=$_POST['subcat']; //-query the database table for the post field $sql="SELECT kit_id, kit_number, kit_name, description_eng, description_fr, manufacturer_kit, manufacturer_reel, manufacturer_reel_id, scale, engine_detail, year_prod_kit, year_prod_reel, image_id, image_id1, image_id2 FROM kit "; $sqlOperand="WHERE"; if ($name != "cat") { $sql = $sql . $sqlOperand . " cat LIKE '%" . $name ."%' "; $sqlOperand = " AND "; } if ($name1 != "kit manufacturer") { $sql = $sql . $sqlOperand . " manufacturer_kit LIKE '%" . $name1 ."%' "; $sqlOperand = " AND "; } if ($name11 != "subcat") { $sql = $sql . $sqlOperand . " subcat LIKE '%" . $name11 ."%' "; $sqlOperand = " AND "; } if ($name2 != "vehicules year manufactured") { $sql = $sql . $sqlOperand . " year_prod_reel LIKE '%" . $name2 ."%' "; $sqlOperand = " AND "; } if ($name3 != "scale") { $sql = $sql . $sqlOperand . " scale LIKE '%" . $name3 ."%' "; $sqlOperand = " AND "; } if ($sqlOperand == "WHERE") { echo "<p>Please enter a search query</p>"; } else { // echo '<img src="web-design/sorry.jpg" alt="sorry">'; // echo "Sorry nothing match your selection / Desolle rien ne correspond a votre selection"; // echo "run sql: <BR> $sql <BR> and display results"; } //-run the query against the mysql query function $result=mysql_query($sql); //-make the header of the table echo " <table align=center width=\"1340\" border=\"\">\n"; echo " <tr>\n"; echo" <td nowrap align=center width='95'> kit manufacturer \n"; echo" <td nowrap align=center width='55'> scale \n"; echo" <td nowrap align=center width='90'> kit number \n"; echo" <td nowrap align=center width='290'> kit name \n"; echo" <td nowrap align=center width='400'> description \n"; echo" <td nowrap align=center width='125'> vehicule year \n"; echo" <td nowrap align=center width='80'> complete engine detail\n"; echo" <td nowrap align=center width='80'> Select Picture to get bigger\n"; echo" <td nowrap align=center width='75'> instruction sheet\n"; echo" <td nowrap align=center width='75'> box contain\n"; echo " <tr>\n"; //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $description_eng =$row['description_eng']; $manufacturer_kit=$row['manufacturer_kit']; $scale=$row['scale']; $manufacturer_reel=$row['manufacturer_reel']; $kit_id=$row['kit_id']; $kit_number=$row['kit_number']; $kit_name=$row['kit_name']; $engine_detail=$row['engine_detail']; $year_prod_reel=$row['year_prod_reel']; $image_id=$row['image_id']; $image_id1=$row['image_id1']; $image_id2=$row['image_id2']; //-create table of item during he while loop echo " <table align=center width=\"1340\" border=\"\">\n"; echo" <td nowrap align=center width='95'> $manufacturer_kit \n"; echo" <td nowrap align=center width='55'> $scale \n"; echo" <td nowrap align=center width='90'> $kit_number \n"; echo" <td nowrap align=center width='290'> $kit_name \n"; echo" <td nowrap width='400'> $description_eng \n"; echo" <td nowrap align=center width='125'> $year_prod_reel \n"; echo" <td nowrap align=center width='80'> $engine_detail \n"; echo" <td nowrap width='80'> <a href=".$image_id."> <img src='".$image_id."' width='75' height='50' border='0'/>"; echo" <td nowrap width='75'> <a href= ".$image_id1."> <img src= 'http://www.scale24-25.com/images/PDF_logo.gif' width='50' height='50' border='0'/>"; echo" <td nowrap width='75'> <a href=".$image_id2."> <img src='http://www.scale24-25.com/images/PDF_logo.gif' width='50' height='50' border='0'/>"; echo " </tr>\n"; echo " </table>\n"; echo " </tr>\n"; echo " </table>\n"; } } else{ echo "<p>Please enter a search query</p>"; } ?> </body> </html> so what I do wrong. I knowI forgot something but what???? thanks in advance for your help sebastien I am getting an error message. Quote mysql_fetch_array(): supplied argument is not a valid MySQL result My Sql seems to work fine. But I kept on getting this error message whenever I try to view orderid. I have option to view different field such as orderid, orderdate, price and profit. When the page loads its fine. But when I try to view orderdate the orderid I get the error message Error code is on the first line and the other places where it says $result. Code: [Select] while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td align='left'>" . $row['orderid'] . "</td>"; echo "<td align='left' style='font-size:12px;'>" . $row['orderdate'] . "</td>"; echo "<td align='left' style='font-size:12px;'>" . $row['updated'] . "</td>"; echo "<td align='left' style='font-size:12px;'>" . $row['name'] . "</td>"; echo "<td align='left' style='font-size:12px;'>" . $row['price'] . "</td>"; echo "<td align='left'>" . $row['salesman'] . "</td>"; echo "<td align='left'>" . $row['origsalesman'] . "</td>"; echo "<td align='left'>" . $row['status'] . "</td>"; echo "<td align='left'>" . $row['product'] . "</td>"; echo "<td align='left'>£" . $row['profit'] . "</td>"; echo "</tr>"; echo "<tr><td colspan='10'><hr></td></tr>"; } if ( mysql_num_rows( $result ) == 0 ) echo "<tr><td colspan='10'>No orders found<hr></td></tr>"; echo "</table></form>"; mysql_free_result( $result );code] Please help me. $getURL = mysql_fetch_assoc(mysql_query("SELECT `urlname` FROM `workingurls` ORDER BY RAND() LIMIT 1")); spits out Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /public_html/script.php on line 130 How do you make mysql_fetch_assoc a valid MySQL result resource? Thanks for reading! I'm working on a site and it won't display my records from the database. I have a little filter system that did work, but now it doesn't. I get the following error message: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/60608.glrdmd.eu/httpdocs/jakesite/select3.php on line 26 Relevant code to the error is: Code: [Select] <?php include("connection.php"); if(isset($_POST['Graphic']) && $_POST['Graphic'] == 'yes') { $result1 = "graphic"; } if(isset($_POST['Interactive']) && $_POST['Interactive'] == 'yes') { $result2 = "interactive"; } if(isset($_POST['Websites']) && $_POST['Websites'] == 'yes') { $result3 = "websites"; } $order = $_POST['group1']; $sql = ("SELECT * FROM 'jake_portfolio' WHERE CAT = '$result1' OR CAT = '$result2' OR CAT = '$result3' ORDER BY '$order' LIMIT 0, 4"); $result = mysql_query($sql); $checked = "checked"; $row = mysql_fetch_array($result); ?> Does anyone see what I am doing wrong here? 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. I get the following error: with the following code: Code: [Select] $username="****"; $password="****"; $database="checkmyw_database"; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query3="SELECT * FROM hours WHERE (out1<>'0' AND in1=='0' OR out2<>'0' AND in2=='0') && (date==$date)"; $result3=mysql_query($query3); $num3=mysql_numrows($result3); mysql_close(); if($num3==0){ $clockedout="true";} echo $clockedout; Any ideas why This is the full error...Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in This is what I am trying to do... 1. get data from the page before which it gets fine in the $_GET function... 2. then set the sersion[username] to $username...(I think I am doing something wrong there) 3. then if the $username doesnt match the username pulled from the database (according to the $_GET info) then open a different databse and update a value in that table. 4. then kill the code die (); someone please help I have been trying to figure this out all day Code: [Select] <?php $username = $_SESSION['username']; $deleted = $_GET['deleted']; // Connect to MySQL $connect = mysql_connect("db","user","pass") or die("Not connected"); mysql_select_db("dv") or die("could not log in"); // grab the information according to the isbn number $query = "SELECT * FROM 'boox' WHERE isbn='$deleted'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { if ($username==$row['username']) { echo"Welcome, ".$_SESSION['username'].""; // Delete entry where isbn number matches accordingly mysql_query("DELETE * FROM 'boox' WHERE isbn='$deleted'"); } elseif ($username!=$row['username']) { $username = $_SESSION['username']; $connect = mysql_connect("db","user","pass") or die("Not connected"); mysql_select_db("db") or die("could not log in"); // run a query to deactivete a account $acti = mysql_query("UPDATE 'desiredusers' SET activated='2' WHERE username='$username'"); $byebye = "SELECT * FROM 'desiredusers' WHERE isbn='$deleted'"; $results = mysql_query($byebye); while($row2 = mysql_fetch_array($results)) echo "here".$username."here"; die("Your account is deactivated contact College Boox Store to get your account back."); } else echo "there is nothing being checked" . $username . ""; } ?> Hi guys, I have this code here working which will show certain data in the table depending on what string the user searches for, and with the records that pop up you are able to delete these records too.. now all this is working but after I delete records I get this error: "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/define/public_html/golf/Pete/php/searchcallback.php on line 22" I assume this is because num rows are empty after the deletion is done/ and this now shows "no records showing" can anyone help me why this error is popping up? Although deletion does work, I would like to get rid of this error message. Code: [Select] <?php include "connect.php"; $searchvalue = $_POST['searchvalue']; $su = $_POST['search']; //Check if records were submitted for deletion if(isset($_POST['callbackid']) && count($_POST['callbackid'])) { //Ensure values are ints $deleteIDs = implode(', ', array_map('intval', $_POST['callbackid'])); $query = "DELETE FROM callback WHERE callbackid IN ({$deleteIDs})"; //Debug line echo "<br/>Successfuly deleted callback(s) <br/>"; mysql_query($query) or die(mysql_error()); } $result = mysql_query("SELECT * FROM callback WHERE $searchvalue LIKE '%$su%'"); $num_rows = mysql_num_rows($result); ?> <link rel="stylesheet" type="text/css" href="view.css" media="all"> <script type="text/javascript" src="view.js"></script> <body id="main_body" > <img id="top" src="top.png" alt=""> <div id="form_container"> <h1>Show, Search or Delete Callback Records<</h1> <form id="form_362567" class="appnitro" method="post" action="searchcallback.php"> <div class="form_description"> <h2> Show, Search or Delete Callback Records</h2> <p></p> </div> <ul > <li class="section_break"> <?php if ($num_rows==0){ ?> <br>No records found<br><br> <INPUT TYPE="button" VALUE="Go Back" onClick="history.go(-1);return true;"><br> <?php } else{ while($row = mysql_fetch_array($result)) { //..results as in your post. echo "<form action='' method='POST'>"; echo "<br/>"; echo "<b>Callback ID:</b>"; echo "<br/>"; echo $row['callbackid']; echo "<br/>"; echo "<b>Full Name:</b>"; echo "<br/>"; echo $row['fullname']; echo "<br/>"; echo "<b>E-mail:</b>"; echo "<br/>"; echo $row['email']; echo "<br/>"; echo "<b>Phone Number:</b>"; echo "<br/>"; echo $row['phone']; echo "<br/>"; echo "<b>Comment:</b>"; echo "<br/>"; echo $row['comment']; echo "<br/>"; echo "<input type='checkbox' name='callbackid[]' value='{$row['callbackid']}' /> <b>Delete</b>\n"; ?> <li class="section_break"> <?php } ?> <br><input type='submit' value='Delete Records' name='delete' /><INPUT TYPE="button" VALUE="Cancel" onClick="history.go(-1);return true;"><br> </form> <div id="footer"> </div> </div> <img id="bottom" src="bottom.png" alt=""> </body> <?php } ?> Thanks for any help in advance |