PHP - Warning: In_array() [function.in-array]: Wrong Datatype For Second Argument
Hello
I'm using tcpdf to convert some stuff to pdf. On my local computer running wamp my script works perfect and the pdf is generated without problems When i put my files in a webserver i got this error: Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/vieira/public_html/topdf/dbcon.class.php on line 68 Line 68 is: if(in_array($key,$arr_switches)){ //check switches My complete code is: // Get fields of enum on/off switches type $result2 = mysql_query("SHOW FIELDS FROM $db_name.$table"); $counter=0; while($row = @mysql_fetch_array($result2)){ //echo $row['Field'] . ' ' . $row['Type']."<br/>"; if($row['Type'] === "enum('on','off')"){ $arr_switches[$counter] = $row['Field']; $counter++; } } //print"<pre>"; print_r($arr_switches); print"</pre>";exit; $counter = 0; while($row = @mysql_fetch_array($result)){ foreach( $row as $key => $val ){ if(!is_numeric($key)) { $row_rs_certidao[$key] = $val; if(in_array($key,$arr_switches)){ //check switches $record_key[$counter] = htmlentities('<?php if (!(strcmp($row_rs_certidao['."'".$key."'".'],"on"))) {echo "x";} ?>'); if($val==='on') $record_val[$counter] = "x"; //turn on switches else $record_val[$counter] = ''; //turn off }else{ $record_key[$counter] = htmlentities('<?php echo $row_rs_certidao['."'".$key."'".']; ?>'); $record_val[$counter] = htmlentities($val); } $counter++; } } } Anyone can help? Similar TutorialsIm getting a warning with in_array.I have used if() inside for loop to check if value has already been printed or not. If not it will print and save the value in $done[].Can someone please point me out my mistake that i am getting a warning. Code: [Select] <?php for($i=0;$i<=$count;$i++) { $count_final = explode("_", $result[$i]); if (in_array($count_final[0],$done)) { //Line 480 echo "<tr>"; echo"<td>$count_final[0]</td>"; $templ = $count_final[0]."_left"; $tempr = $count_final[0]."_right"; $cleft = $count_middle[$templ]; $cright = $count_middle[$tempr]; echo"<td>$cright</td>"; echo"<td>$cleft</td>"; echo "</tr>"; $done[] = $count_final[0]; } } ?> Code: [Select] Warning: in_array() [function.in-array]: Wrong datatype for second argument in C:\Users\\Desktop\yyy.php on line 480 I am having some problems getting a query correct. Basically I have two tables, one with listings and another with categories. In the listings table I have a column called shortdescription. I am trying to pull the shortdescription from the listings table with the query $shortdesc = array_shift(mysql_fetch_row(mysql_query("select shortdescription from links where category = '".$scat->id."' "))); The shortdecription display properly on the pages display the listings, however I am getting the following error on any pages that only display the parent categories Warning: array_shift() [function.array-shift]: The argument should be an array in /home/...path/file.php on line 1462 The listings id numbers begin at 75+ because the initial parent category id ends at 74. The query seems to be searching for listing ids below 75 and spitting out an error because it is not finding them. Any ideas on how to eliminate this error and/or stop the query from looking for non-existant data? I have been scripting (some may say programming) in PHP for last 5 years but never faced this issue. Interesting! Say for example, I created a custom function with one argument: function myFunc($arg1) { echo $arg1; } Now, if I call this function without supplying any argument it doesn't give any error/warning. Any other high level language like C++ or Java would produce error in this case. So, I had to modify my code as follows: function myFunc($arg1) { if (!isset($arg1)) { echo "Missing argument 1"; } echo $s; } But this is annoying. Now I have to add these EXTRA lines of code in every function and class methods I have created. Is there any shortcut/easy method that the script will always produce an error if its missing any required argument? I have tried with adding error_reporting(E_ALL); at the very beginning of my code. But it still didn't work out. By the way, I am using PHP 5.3.1 on Apache/2.2.14 (Unix). Any suggestion will be appreciated. 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 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. Hey there, This has me stumped here. I'm supplying an array as a valid argument to the class like so: $mysql_configuration = array( 'MySQL_Host' => "localhost", 'MySQL_Username' => "fdsfdsfsdfsd", 'MySQL_Password' => "sdf-sdf543", 'MySQL_Database' => "sfsdfsdfsdf"); $radio_core = array('Main' => new Radio_Core($mysql_configuration), 'Requests' => new Radio_Requests, 'Accounts' => new Radio_Accounts, 'Content' => new Radio_Content); And here is my small class: class Radio_Core { public $mysql_handle; function __construct($mysql_array) { $this->mysql_handle = mysql_connect($mysql_array['MySQL_Host'], $mysql_array['MySQL_Username'], $mysql_array['MySQL_Password']); if(!$this->mysql_handle) { die("The station failed to connect to the MySQL database."); } else { mysql_select_db($mysql_array['MySQL_Database'], $this->mysql_handle); } return 1; } } And when it is called I am prompted with the error that the argument is missing for it? Quote Warning: Missing argument 1 for Radio_Co :__construct(), called in /home/atomnetw/public_html/Chris-Martino.com/projects/radio/index.php on line 10 and defined in /home/atomnetw/public_html/Chris-Martino.com/projects/radio/Core/radio.class.php on line 15 Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'atomnetw'@'localhost' (using password: NO) in /home/atomnetw/public_html/Chris-Martino.com/projects/radio/Core/radio.class.php on line 17 Thanks for your time! 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 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 " "; } } ?> This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=355998.0 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. 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, 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>"; ?> 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 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 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, 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); ?> Hi all, complete newbie here. i have copied this example php code to insert data and a picture into a mysql database. however i get this error. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource can be seen here : http://wycombedjs.co.uk/mix/sqltest.php Any help would be much appreciated.. thanks Code: [Select] <?php $db_host = 'xxx'; // don't forget to change $db_user = 'xxx'; $db_pwd = 'xxx'; $database = 'mixdb'; $table = 'ae_gallery'; // use the same name as SQL table $password = '123'; // simple upload restriction, // to disallow uploading to everyone if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); // This function makes usage of // $_GET, $_POST, etc... variables // completly safe in SQL queries function sql_safe($s) { if (get_magic_quotes_gpc()) $s = stripslashes($s); return mysql_real_escape_string($s); } // If user pressed submit in one of the forms if ($_SERVER['REQUEST_METHOD'] == 'POST') { // cleaning title field $title = trim(sql_safe($_POST['title'])); if ($title == '') // if title is not set $title = '(empty title)';// use (empty title) string if ($_POST['password'] != $password) // cheking passwors $msg = 'Error: wrong upload password'; else { if (isset($_FILES['photo'])) { @list(, , $imtype, ) = getimagesize($_FILES['photo']['tmp_name']); // Get image type. // We use @ to omit errors if ($imtype == 3) // cheking image type $ext="png"; // to use it later in HTTP headers elseif ($imtype == 2) $ext="jpeg"; elseif ($imtype == 1) $ext="gif"; else $msg = 'Error: unknown file format, .png, .jpeg, .gif only!'; if (!isset($msg)) // If there was no error { $data = file_get_contents($_FILES['photo']['tmp_name']); $data = mysql_real_escape_string($data); // Preparing data to be used in MySQL query mysql_query("INSERT INTO {$table} SET ext='$ext', title='$title', data='$data'"); $msg = 'Success: image uploaded to Mix db'; } } elseif (isset($_GET['title'])) // isset(..title) needed $msg = 'Error: file not loaded';// to make sure we've using // upload form, not form // for deletion if (isset($_POST['del'])) // If used selected some photo to delete { // in 'uploaded images form'; $id = intval($_POST['del']); mysql_query("DELETE FROM {$table} WHERE id=$id"); $msg = 'Photo deleted'; } } } elseif (isset($_GET['show'])) { $id = intval($_GET['show']); $result = mysql_query("SELECT ext, UNIX_TIMESTAMP(image_time), data FROM {$table} WHERE id=$id LIMIT 1"); if (mysql_num_rows($result) == 0) die('no image'); list($ext, $image_time, $data) = mysql_fetch_row($result); $send_304 = false; if (php_sapi_name() == 'apache') { // if our web server is apache // we get check HTTP // If-Modified-Since header // and do not send image // if there is a cached version $ar = apache_request_headers(); if (isset($ar['If-Modified-Since']) && // If-Modified-Since should exists ($ar['If-Modified-Since'] != '') && // not empty (strtotime($ar['If-Modified-Since']) >= $image_time)) // and grater than $send_304 = true; // image_time } if ($send_304) { // Sending 304 response to browser // "Browser, your cached version of image is OK // we're not sending anything new to you" header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ts).' GMT', true, 304); exit(); // bye-bye } // outputing Last-Modified header header('Last-Modified: '.gmdate('D, d M Y H:i:s', $image_time).' GMT', true, 200); // Set expiration time +1 year // We do not have any photo re-uploading // so, browser may cache this photo for quite a long time header('Expires: '.gmdate('D, d M Y H:i:s', $image_time + 86400*365).' GMT', true, 200); // outputing HTTP headers header('Content-Length: '.strlen($data)); header("Content-type: image/{$ext}"); // outputing image echo $data; exit(); } ?> <html><head> <title>MySQL Blob Image Gallery Example</title> </head> <body> <?php if (isset($msg)) // this is special section for // outputing message { ?> <p style="font-weight: bold;"><?=$msg?> <br> <a href="<?=$PHP_SELF?>">reload page</a> <!-- I've added reloading link, because refreshing POST queries is not good idea --> </p> <?php } ?> <h1>Blob image gallery</h1> <h2>Uploaded images:</h2> <form action="<?=$PHP_SELF?>" method="post"> <!-- This form is used for image deletion --> <?php $result = mysql_query("SELECT id, image_time, title FROM {$table} ORDER BY id DESC"); if (mysql_num_rows($result) == 0) // table is empty echo '<ul><li>No images loaded</li></ul>'; else { echo '<ul>'; while(list($id, $image_time, $title) = mysql_fetch_row($result)) { // outputing list echo "<li><input type='radio' name='del' value='{$id}'>"; echo "<a href='{$PHP_SELF}?show={$id}'>{$title}</a> – "; echo "<small>{$image_time}</small></li>"; } echo '</ul>'; echo '<label for="password">Password:</label><br>'; echo '<input type="password" name="password" id="password"><br><br>'; echo '<input type="submit" value="Delete selected">'; } ?> </form> <h2>Upload new image:</h2> <form action="<?=$PHP_SELF?>" method="POST" enctype="multipart/form-data"> <label for="title">Title:</label><br> <input type="text" name="title" id="title" size="64"><br><br> <label for="photo">Photo:</label><br> <input type="file" name="photo" id="photo"><br><br> <label for="password">Password:</label><br> <input type="password" name="password" id="password"><br><br> <input type="submit" value="upload"> </form> </body> </html> |