PHP - $1 Argument
Hi all,
I don't know php, but i have a script i would like to be able to also run from shell, like: "php script arg1"... if (isset($_SERVER['argc'])) { $postip = $1; } else { $postip = $_POST["ip"]; } How do i assign $postip = $1; (or is it infact $2...) ? My script gives me this error now: PHP Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' Thanks in advance :-) ! Similar TutorialsFor some reason I keep getting a recurring error every time someone uses a page on my site. Here is the error: Code: [Select] [Date] PHP Warning: array_key_exists() [<a href='function.array-key-exists'>function.array-key-exists</a>]: The second argument should be either an array or an object in /home/page.php on line 52 The offending line is he Code: [Select] echo array_key_exists($i, $alpha) ? '<li><a href="?a=show&letter='.$i.'&type='.$type.'">'.$i.'</a></li> ' : '<li class="no_highlight">'.$i.'</li> The code works, but the error message must be showing that I am performing the echo incorrectly. Anyone have any ideas on where I could be going wrong (other than the exact line, that is )? Here's the rest of the code for full reference (the offending line is near the top). Thanks for any help! Code: [Select] <?php $sql = "SELECT *, UPPER(SUBSTRING(series,1,1)) AS letter FROM design WHERE type = '$type' ORDER BY series"; $query = mysql_query($sql) or die(mysql_error()); // Display a range of letters. echo '<ul class="alphabet">'; while ($records = mysql_fetch_assoc($query)) { $alpha[$records['letter']] += 1; ${$records['letter']}[$records['series']] = $records['series']; } foreach(range('A','Z') AS $i) { echo array_key_exists($i, $alpha) ? '<li><a href="?a=show&letter='.$i.'&type='.$type.'">'.$i.'</a></li> ' : '<li class="no_highlight">'.$i.'</li> '; echo $i != 'Z' ? ' ':'</ul>'; } // Display records of the letter selected. if (isset($_GET['letter']) && !empty($_GET['letter']) && !is_numeric($_GET['letter'])) { $letter = substr($_GET['letter'], 0, 1); } else { $letter = ''; } $a = (isset($_GET['a'])) ? strip_tags(trim(htmlentities($_GET['a'], ENT_QUOTES))) : 'index'; switch ($a) { case 'index': $select_series = mysql_query("SELECT *, UPPER(SUBSTRING(series,1,1)) AS letter FROM design WHERE `type` = '$type' ORDER BY `id` DESC LIMIT 8") or die (mysql_error()); $i=3; echo '<h3>Newest Additions</h3>'; while($row2 = mysql_fetch_array($select_series)) { extract ($row2); $contents_here = '<div class="envelope"><a href="?a=show&letter='.$letter.'&type='.$type.'#'.$title.'"><img src="previews/'.$id.'.jpg" class="tips" title="'.$title.'|'.$series.'"><br>'.$title.'</a></div>'; if ($i==0) { echo ''.$contents_here.''; } else if ($i==3) { echo ''.$contents_here.''; } else { echo ''.$contents_here.''; } $i++; $i=$i%3; } break; case 'show': $letter2 = (isset($_GET['letter'])) ? strip_tags(trim(htmlentities($_GET['letter'], ENT_QUOTES))) : ''; $sql = "SELECT * ,UPPER(SUBSTRING(series,1,1)) AS letter, date_format(design.datetime, '%M %d, %Y') AS datetime FROM design WHERE series LIKE '$letter2%' AND type = '$type' ORDER BY series ASC, id ASC"; $query = mysql_query($sql) or die (mysql_error()); echo '<h3><a name="'.$i.'"><b>'.$letter.'</b></a></h3> <table align="center" width="100%"><tr><td>'; $series = ''; while ($row = mysql_fetch_assoc($query)) { $image = $row[image]; $datetime = $row[datetime]; $id = $row[id]; $type = $row[type]; $title = $row[title]; $count_display = $row[count_display]; if ($series != $row['series']) { //Assign category to holding var $series = $row['series']; //echo Category heading echo '<h3><a href="#" class="top"></a>'.$series.'</h3> '; } echo '<table align="center" class="format" cellpadding="0" cellspacing="0"> <tr><td> <img src="previews/'.$id.'.jpg" align="right"> <td class="design"><ul class="design_info"> <li class="special"><b>Title:</b> <a name="'.$title.'">'.$title.'</a> <ul> <li><b>Series:</b> '.$series.' <li><b>Type:</b> '.$type.' <li><b>Uploaded:</b> '.$datetime.' <li><b>Downloads:</b> '.$count_display.' </ul></ul> <ul class="design_dl"> <li class="preview"><a href="graphics/preview.php?id='.$id.'" target="_blank">preview</a> <li class="download"><a href="graphics/download.php?id='.$id.'">download</a> </ul> </td></tr> </table>'; } } echo '</table>'; ?> Hi, I am attempting to export some table data to an excel spreadsheet. I am having trouble with the final few lines and getting the following error within the spreadsheet (which is otherwise working well). Quote The argument should be an array in/home/website/public_html/student_list_export.php on line 34 I get the same error message for the line below also (echo implode("\t", array_values($row)) . "\n". I'm at a loss. This seems like a pretty obvious and direct error message but I can't get it working properly. Can somebody please help me? Below is the code I am working with. <?php include('includes/admin_session.php'); require_once("includes/connection.php"); function cleanData(&$str) { $str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $str); if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; } // file name for download $filename = "student_list_" . date('Ymd') . ".xls"; header("Content-Disposition: attachment; filename=\"$filename\""); header("Content-Type: application/vnd.ms-excel"); $flag = false; $result = mysqli_query($connection,"SELECT * FROM students ORDER BY tutor") or die(mysqli_error($connection)); while(false !== ($row = mysqli_fetch_assoc($result))) { if(!$flag) { // display field/column names as first row echo implode("\t", array_keys($row)) . "\n"; $flag = true; } array_walk($row, 'cleanData'); echo implode("\t", array_values($row)) . "\n"; } ?> 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'm getting this error, but I'm not sure how to fix it (on my Wordpress site). Warning: usort() [function.usort]: The argument should be an array in /home2/lushwebs/public_html/4mulaevents/wp-content/themes/dailyedition/includes/talking-points.php on line 20 Warning: Invalid argument supplied for foreach() in /home2/lushwebs/public_html/4mulaevents/wp-content/themes/dailyedition/includes/talking-points.php on line 22 Any help appreciated. Thanks! How do I make my constructor work when I don't pass in an argument. That is, it should efault to null. Code: [Select] class Something{ private $type=null; public function __construct($t){ $this->type = $t; } public function setSomething($t){ $this->type = $t; } public function getSomething(){ if (is_null($this->type)) { return "None for you!"; } else { return "Something is " . $this->type . "."; } } } TomTees Hey all. I have a function called displayForm in a form validation script. This function accepts a few arguments but these arguments are empty upon initial calling of the function. One of the arguments is and errors array that only gets populated if there were form errors. So upon running my script initially I get missing argument Warnings. Can these warnings simply be ignored? Would they cause problems throughout my script if I ignore these warnings? And how can I suppress these warnings if I would like to? Thanks all for your help. Cheers. I've been challenging myself to get the system() argument working for the past hour and something. I still can't get it working so I ask for assistance. system ("cp /var/www/http/test.com/products/".$fordir['fordir']."/".$category['category']."/".$_POST['id']." /home/n/Documents/My\ Sites/test.com\ codebase"); The error log doesn't say anything, so I suspect that PHP is not even attempting to parse the code. Can anyone spot something that shouldn't be the way it is? Hello, i know this is a very silly question but it bothers me to know the reasoning behind it. My application has a design where the functions are stored in functions.php and variables are stored in variables.php. There are some functions that have variables that i might change often and the reason i don't directly use them in the argument itself is so that in future if i have to change the default argument's value , then i wouldn't have to scroll through all the functions and look for it. I have a slippery memory i know i will be able to remember it better if i store custom global variables separately and custom global functions separately. I tried searching these forums for this but its giving me a message like "search daemon not found" or something like that.. Anyways , coming to the point, i know that PHP doesn't accept variables as default arguments but may i know the reasoning behind this? If i understand the reasoning behind this i know it will stick better in my head.So..why does a function not allow a variable as a default value? Or if anyone has a link to explaining this behaviour in PHP, i would appreciate it if you could pass it on! Thank you Firstly i am new to php.Iv currently got this while loop iterating through a database drawing polygons from the info in the datatable.each polygon has its own id stored in the datatable and with the on click event i am trying to just output to the screen the specific id of the polygon clicked on.It looks ok to me but it doesnt work for some reason. Below is the loop and the function it is trying to call. /////////////////////////////////////////////////////////////////////// <?php while($info = mysql_fetch_array( $data )){ echo "<polygon fill=".$info['fill_colour']." stroke=\"black\" id=".$info['id']." onclick=\"buildingClick(id)\" points=".$info['coordinates']." />"; } ?> ///////////THIS IS THE FUNCTION/////////////////////////// <?php function buildingClick($id) { echo "building id : {$id}"; } ?> /////////////////////////////////////////////////////////////////// If anyone could help it would be hugely appreciated. Eoin 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 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); } ?> 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 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 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. Hey guy's, have been stuck at this hurdle for a little whole now and I can't seem to find the right solution and would very much appreciate anyones help on this. Ok, so I have a table of votes and each time a user votes, they're added to this table. Now, I have a 'pool' table which will display certain items. What I'm trying to do is display the 'pool' items, but if this specific user has already voted on this particular item, then I want it to skip the item in the 'pool' and go to the next item, until the argument of has that user voted is false. The current code I'm pasting will obviously not work, it isn't even in the right position, but I've separated it so that you can hopefully understand what I'm trying to do in order to help. Below is the code I use to check if a user has already voted on a particular photo: <?php $result=mysql_query("SELECT * FROM votes WHERE vVoter='$_SESSION[userID]' AND vPhoto='$_SESSION[currentphoto]'"); $rowCheck = mysql_num_rows($result); $alreadyv = 0; if($rowCheck > 0){ $alreadyv = 1; //user has already voted on this photo, need to use this info to be able to skip it in the 'pool' } else { //do nothing } ?> totalVoted is basically how many times a user has voted, so that people who vote more, get more votes: <?php $result=mysql_query("SELECT * FROM pool ORDER BY totalVoted DESC LIMIT 1"); $rowCheck = mysql_num_rows($result); if($rowCheck > 0){ while($row = mysql_fetch_array($result)){ $photoid = $row['photoInPool']; $result2=mysql_query("SELECT * FROM photos WHERE pID='$photoid'"); $rowCheck2 = mysql_num_rows($result2); if($rowCheck2 > 0){ while($row2 = mysql_fetch_array($result2)){ if($alreadyv == 1) { //I NEED THIS TO SHOW THE NEXT PHOTO IN THE ARRAY, HOWEVER, IF THEY HAVE ALREADY VOTED ON THE NEXT PHOTO, IT WILL STILL DISPLAY IT, THIS IS MY PROBLEM I NEED HELP WITH PLEASE } elseif ($alreadyv != 1) { $fname = $row2['pFileName']; } } } $_SESSION[currentphoto] = $row['photoInPool']; echo "<center><img src='user_images/$fname'></center>"; } } ?> I hope I've explained this well enough and hope somebody can help. Many thanks in advance 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 Hi, I am a beginner with php and I am having a hard time understanding a section in my code. The part I dont get is why we have to minus 1 from the number being passed into the array. For example, $FaceNamePlural[$die1-1] I tried looking at it over and over but I'm still very confused. Can anyone help me on this...Thanks. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php $FaceNameSingular = array("one", "two", "three", "four", "five", "six"); $FaceNamePlural = array("ones", "twos", "threes", "fours", "fives", "sixs"); function CheckForDoubles($die1, $die2) { global $FaceNameSingular; global $FaceNamePlural; if($die1 == $die2) // doubles echo "The roll was double ", $FaceNamePlural[$die1-1], "<br />"; if($die1 != $die2) //not doubles echo "The roll was a ", $FaceNameSingular[$die1-1], " and a ", $FaceNameSingular[$die2-1], ".<br />"; } function DisplayScoreText($Score) { if($Score == 2) echo "you roll snake eyes! <br />"; if($Score == 3) echo "you roll loose duece! <br />"; if($Score == 5) echo "you roll fever five! <br />"; if($Score == 7) echo "you roll natural! <br />"; if($Score == 9) echo "you roll nina! <br />"; if($Score == 11) echo "you roll yo! <br />"; if($Score == 12) echo "you roll boxcars! <br />"; } $dice = array(); $dice[0] = rand(1,6); $dice[1] = rand(1,6); $Score = $dice[0] + $dice[1] ; echo "<p>"; echo "The total score for the roll was $Score . <br />"; CheckForDoubles($dice[0],$dice[1]); DisplayScoreText($Score); echo "</p>"; ?> </body> </html> 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)); } ?> 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); ?> 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'])) { |