kclark Posted December 20, 2010 Share Posted December 20, 2010 I am using this file with joomla. The database connection is code at the top of the php. I am getting the following error and I don't know why. Warning: extract() [function.extract]: First argument should be an array in /usr/local/4admin/apache/vhosts/ladystestsite.com/httpdocs/php/obitdisplay.php on line 18 I have a query that is commented out and that will work, but I need the larger query to work. It has been working, but nothing has changed. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/ Share on other sites More sharing options...
Maq Posted December 20, 2010 Share Posted December 20, 2010 Please post the relevant code. Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149552 Share on other sites More sharing options...
kclark Posted December 20, 2010 Author Share Posted December 20, 2010 // Get a database object $db = JFactory::getDBO(); //$query = "SELECT * FROM deceasedlist where ID = '$_GET[iD]'"; $query = "SELECT deceasedlist.ID, deceasedlist.DFirstName, deceasedlist.DLastName, deceasedlist.Birth, deceasedlist.Death, deceasedlist.location, deceasedlist.funeral, deceasedlist.visitation, deceasedlist.receivingplace_id, deceasedlist.funeralplace_id, deceasedlist.cemeteryplace_id, deceasedlist.funeraldate, deceasedlist.Picture, deceasedlist.Obit1, deceasedlist.Obit2, deceasedlist.Obit3, deceasedlist.Obit4, deceasedlist.Obit5, deceasedlist.Obit6, deceasedlist.Obit7, deceasedlist.Obit8, places.place_name AS funeralplace, places.address AS funeralplaceaddress, places.city AS funeralplacecity, places.state AS funeralplacestate, places.zip AS funeralplacezip, places.country AS funeralplacecountry, places_1.place_name AS receivingplace, places_1.address AS receivingplaceaddress, places_1.city AS receivingplacecity, places_1.state AS receivingplacestate, places_1.zip AS receivingplacezip, places_1.country AS receivingplacecountry, places_2.place_name AS cemeteryplace, places_2.address AS cemeteryplaceaddress, places_2.city AS cemeteryplacecity, places_2.state AS cemeteryplacestate, places_2.zip AS cemeteryplacezip, places_2.country AS cemeteryplacecountry FROM deceasedlist INNER JOIN places ON deceasedlist.funeralplace_id = places.place_id INNER JOIN places AS places_1 ON deceasedlist.receivingplace_id = places_1.place_id INNER JOIN places AS places_2 ON deceasedlist.cemeteryplace_id = places_2.place_id WHERE deceasedlist.ID = '$_GET[iD]'"; $result = mysql_query($query) or die("Couldn't execute query."); $row = mysql_fetch_array($result); extract($row); Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149557 Share on other sites More sharing options...
Pikachu2000 Posted December 20, 2010 Share Posted December 20, 2010 The query is probably returning an empty result set. You should check for that with mysql_num_rows() before trying to extract() the result. Also, why do you define $query twice? The first one is immediately overwritten by the second. Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149622 Share on other sites More sharing options...
kclark Posted December 20, 2010 Author Share Posted December 20, 2010 I don't have 2 queries, the first was just a sample that I had. I commented it out. At least it is suppose to be. But anyway, the recordset exists, as you must click on the name on a previous php page to get the details of the individual. If I use the query that is commented out, everything is right. But I have been using the 2nd query since March. Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149627 Share on other sites More sharing options...
Pikachu2000 Posted December 20, 2010 Share Posted December 20, 2010 Yeah, I see it now. Phone screen is narrow, so it dropped the whole $query line to the next line and left the // above it . . . Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149630 Share on other sites More sharing options...
DavidAM Posted December 20, 2010 Share Posted December 20, 2010 The error says that the parameter ($row) to extract is not an array. Since $row is assigned from mysql_fetch_array() we know it will either be an array or it will be a boolean value of false. Since it is not an array, it must be false. mysql_fetch_array() will return false if there is no row to fetch. Since mysql_query() did not error off (which would have caused the "or die()" to execute), we know that the query is syntactically correct but did not return any rows. The most likely reason would be the JOINs or the WHERE clause. Since the WHERE clause is shorter (and I don't know the table structure) we look closely at that. You have: "... WHERE deceasedlist.ID = '$_GET[iD]'"; When you put a variable inside a double-quoted string, PHP should interpret that variable and replace it with the value. One caveat is that when the variable is complex (like an array) you have to put curly braces around the variable so PHP can recognize it and delineate it correctly. However, in this case, curly braces alone may not fix it. You have the array index as ID, unless you have a defined constant named ID somewhere above this code, that line is in error (ok, it's a warning, but those are bad, too). (I'm not sure that PHP will recognize constants in a variable in a double-quoted string, I've never tried it.) You need to put single-quotes around the ID index so PHP can correctly evaluate your variable. So that part of the query should be: "... WHERE deceasedlist.ID = '{$_GET['ID']}'"; Having said that, I highly discourage the use of user supplied data directly in a query. This leaves you open to SQL injection attacks. You need to sanitize that value and make sure it is something you are expecting. If the deceasedlist.ID column is an integer, I would (at the very least) use something like this: $id = intval($_GET['ID']); $query = "... WHERE deceasedlist.ID = '$id'"; Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149668 Share on other sites More sharing options...
BlueSkyIS Posted December 20, 2010 Share Posted December 20, 2010 note: curly braces are not necessary to delineate an array value within a string. The SQL is valid as written. However, the key should definitely be quoted. $_GET['ID'] Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149672 Share on other sites More sharing options...
Maq Posted December 20, 2010 Share Posted December 20, 2010 note: curly braces are not necessary to delineate an array value within a string. The SQL is valid as written. However, the key should definitely be quoted. $_GET['ID'] If you use single quotes in your array key you must use curly braces to escape it. Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149674 Share on other sites More sharing options...
kclark Posted December 20, 2010 Author Share Posted December 20, 2010 If I use this it works: <?php // Get a database object $db = JFactory::getDBO(); $query = "SELECT * FROM deceasedlist where ID = '$_GET[iD]'"; $result = mysql_query($query) or die("Couldn't execute query."); $num_results = mysql_num_rows($result); $row = mysql_fetch_array($result); extract($row); ?> If I use this, it doesn't <?php // Get a database object $db = JFactory::getDBO(); $query = "SELECT deceasedlist.ID, deceasedlist.DFirstName, deceasedlist.DLastName, deceasedlist.Birth, deceasedlist.Death, deceasedlist.location, deceasedlist.funeral, deceasedlist.visitation, deceasedlist.receivingplace_id, deceasedlist.funeralplace_id, deceasedlist.cemeteryplace_id, deceasedlist.funeraldate, deceasedlist.Picture, deceasedlist.Obit1, deceasedlist.Obit2, deceasedlist.Obit3, deceasedlist.Obit4, deceasedlist.Obit5, deceasedlist.Obit6, deceasedlist.Obit7, deceasedlist.Obit8, places.place_name AS funeralplace, places.address AS funeralplaceaddress, places.city AS funeralplacecity, places.state AS funeralplacestate, places.zip AS funeralplacezip, places.country AS funeralplacecountry, places_1.place_name AS receivingplace, places_1.address AS receivingplaceaddress, places_1.city AS receivingplacecity, places_1.state AS receivingplacestate, places_1.zip AS receivingplacezip, places_1.country AS receivingplacecountry, places_2.place_name AS cemeteryplace, places_2.address AS cemeteryplaceaddress, places_2.city AS cemeteryplacecity, places_2.state AS cemeteryplacestate, places_2.zip AS cemeteryplacezip, places_2.country AS cemeteryplacecountry FROM deceasedlist INNER JOIN places ON deceasedlist.funeralplace_id = places.place_id INNER JOIN places AS places_1 ON deceasedlist.receivingplace_id = places_1.place_id INNER JOIN places AS places_2 ON deceasedlist.cemeteryplace_id = places_2.place_id WHERE deceasedlist.ID = '$_GET[iD]'"; $result = mysql_query($query) or die("Couldn't execute query."); $num_results = mysql_num_rows($result); $row = mysql_fetch_array($result); extract($row); ?> Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149677 Share on other sites More sharing options...
kclark Posted December 20, 2010 Author Share Posted December 20, 2010 okay, using phpMyadmin, I get this error using my long sql #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"SELECT deceasedlist.ID, deceasedlist.DFirstName, deceasedlist.DLastNam' at line 1 Nevermind I had an extra quote using phpmyadmin, still have my error on my webpage though. Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149678 Share on other sites More sharing options...
btherl Posted December 20, 2010 Share Posted December 20, 2010 kclark, have you checked $num_results? You cannot extract a row unless $num_results > 0. When you join tables together using "INNER JOIN", results will only exist if there is data in ALL joined tables. If any table has the data missing, you will get nothing. Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149681 Share on other sites More sharing options...
kclark Posted December 20, 2010 Author Share Posted December 20, 2010 The data does exist. I put the records in and they are displayed on a page by name. You click on a name to get the FULL record. so the record has to exist in order for the name to appear in the first place. The other tables for the inner join contains records, because they are used in adding the name records as they are dynamic list boxes used in the records. Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149688 Share on other sites More sharing options...
PFMaBiSmAd Posted December 20, 2010 Share Posted December 20, 2010 After you corrected the syntax error due to the extra quote in Reply #10, what did the query return when executed through phpmyadmin? Edit: And what you do get when you echo $query, because it seems like your $_GET parameter might not contain what you expect. Perhaps you are forming links that have white-space or non-printing characters that would result in a FALSE where term. Edit2: Also, what does var_dump($_GET[iD]); show? Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149689 Share on other sites More sharing options...
kclark Posted December 21, 2010 Author Share Posted December 21, 2010 When I use this: var_dump($_GET[iD]); I get this: string(6) "120902" When I use this: echo $query I get this: SELECT deceasedlist.ID, deceasedlist.DFirstName, deceasedlist.DLastName, deceasedlist.Birth, deceasedlist.Death, deceasedlist.location, deceasedlist.funeral, deceasedlist.visitation, deceasedlist.receivingplace_id, deceasedlist.funeralplace_id, deceasedlist.cemeteryplace_id, deceasedlist.funeraldate, deceasedlist.Picture, deceasedlist.Obit1, deceasedlist.Obit2, deceasedlist.Obit3, deceasedlist.Obit4, deceasedlist.Obit5, deceasedlist.Obit6, deceasedlist.Obit7, deceasedlist.Obit8, places.place_name AS funeralplace, places.address AS funeralplaceaddress, places.city AS funeralplacecity, places.state AS funeralplacestate, places.zip AS funeralplacezip, places.country AS funeralplacecountry, places_1.place_name AS receivingplace, places_1.address AS receivingplaceaddress, places_1.city AS receivingplacecity, places_1.state AS receivingplacestate, places_1.zip AS receivingplacezip, places_1.country AS receivingplacecountry, places_2.place_name AS cemeteryplace, places_2.address AS cemeteryplaceaddress, places_2.city AS cemeteryplacecity, places_2.state AS cemeteryplacestate, places_2.zip AS cemeteryplacezip, places_2.country AS cemeteryplacecountry FROM deceasedlist INNER JOIN places ON deceasedlist.funeralplace_id = places.place_id INNER JOIN places AS places_1 ON deceasedlist.receivingplace_id = places_1.place_id INNER JOIN places AS places_2 ON deceasedlist.cemeteryplace_id = places_2.place_id WHERE deceasedlist.ID = '120902' But I still have this error on my page: Warning: extract() [function.extract]: First argument should be an array in file location on line 17 Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149737 Share on other sites More sharing options...
kclark Posted December 21, 2010 Author Share Posted December 21, 2010 Here is my whole page <?php // Get a database object $db = JFactory::getDBO(); $query = "SELECT deceasedlist.ID, deceasedlist.DFirstName, deceasedlist.DLastName, deceasedlist.Birth, deceasedlist.Death, deceasedlist.location, deceasedlist.funeral, deceasedlist.visitation, deceasedlist.receivingplace_id, deceasedlist.funeralplace_id, deceasedlist.cemeteryplace_id, deceasedlist.funeraldate, deceasedlist.Picture, deceasedlist.Obit1, deceasedlist.Obit2, deceasedlist.Obit3, deceasedlist.Obit4, deceasedlist.Obit5, deceasedlist.Obit6, deceasedlist.Obit7, deceasedlist.Obit8, places.place_name AS funeralplace, places.address AS funeralplaceaddress, places.city AS funeralplacecity, places.state AS funeralplacestate, places.zip AS funeralplacezip, places.country AS funeralplacecountry, places_1.place_name AS receivingplace, places_1.address AS receivingplaceaddress, places_1.city AS receivingplacecity, places_1.state AS receivingplacestate, places_1.zip AS receivingplacezip, places_1.country AS receivingplacecountry, places_2.place_name AS cemeteryplace, places_2.address AS cemeteryplaceaddress, places_2.city AS cemeteryplacecity, places_2.state AS cemeteryplacestate, places_2.zip AS cemeteryplacezip, places_2.country AS cemeteryplacecountry FROM deceasedlist INNER JOIN places ON deceasedlist.funeralplace_id = places.place_id INNER JOIN places AS places_1 ON deceasedlist.receivingplace_id = places_1.place_id INNER JOIN places AS places_2 ON deceasedlist.cemeteryplace_id = places_2.place_id WHERE deceasedlist.ID = '$_GET[iD]'"; $result = mysql_query($query) or die("Couldn't execute query."); $row = mysql_fetch_array($result); //extract($row);This is the line that is giving me problems echo $row['ID'];This line returns the correct ID # that was passed from previous page. var_dump($_GET[iD]);This line repeats my sql statement with the correct ID # in the ID equals statement print "<center> <table width=\"400\"> <tr><td>"; print "<form action='./sendcondolence?ID=$ID' method=\"post\" name=\"FormName\"><input type=\"submit\" value=\"Send A Condolence\" border=\"0\"></form></td><td><form action='./condolences?ID=$ID' method=\"post\" name=\"FormName\"><input type=\"submit\" value=\"View Condolences\" border=\"0\"></form></td> </tr> </table> </center><br><br><center>"; if($Picture == "") print "";if($Picture != "") print "<img src=\"$Picture\" alt=\"$DFirstName $DLastName\" height=\"169\" width=\"133\" border=\"0\"><br>"; print "<b>$DFirstName $DLastName</b></center>"; print "<br><br> <b>Born</b>: "; print date('F j, Y',strtotime($Birth)); print "<br> <b>Died</b>: "; print date('F j, Y',strtotime($Death)); print "<br><br>"; print $Location; print "<br><br>"; $today=date("Y-m-d"); if ($receivingplace_id > 0 && $funeraldate >= $today) print $visitation; if ($receivingplace_id >= 1 && $funeraldate >= $today) print " <a href=\"http://www.mapquest.com/maps/map.adp?city=".$receivingplacecity."&state=".$receivingplacestate."&address=".$receivingplaceaddress."&zip=".$receivingplacezip."&country=".$receivingplacecountry."&zoom=9\" target=\"_blank\"><u>" .$receivingplace. " (map/directions)</u></a><br>"; if ($funeralplace_id > 0 && $funeraldate >= $today) print $funeral; if ($funeralplace_id > 1 && $funeraldate >= $today) print " <a href=\"http://www.mapquest.com/maps/map.adp?city=".$funeralplacecity."&state=".$funeralplacestate."&address=".$funeralplaceaddress."&zip=".$funeralplacezip."&country=".$funeralplacecountry."&zoom=9\" target=\"_blank\"><u>" .$funeralplace. " (map/directions)</u></a><br>"; if ($cemeteryplace_id > 0 &&$funeraldate >= $today) print "Cemetery Location:"; if ($cemeteryplace_id > 1 && $funeraldate >= $today) print " <a href=\"http://www.mapquest.com/maps/map.adp?city=".$cemeteryplacecity."&state=".$cemeteryplacestate."&address=".$cemeteryplaceaddress."&zip=".$cemeteryplacezip."&country=".$cemeteryplacecountry."&zoom=9\" target=\"_blank\"><u>" .$cemeteryplace. " (map/directions)</u></a><br>"; print "<br><br> <html><body background=\"../../Obit Pics/veteran.jpg\"><p align=\"justify\">$Obit1 <br><br> $Obit2 <br><br> $Obit3 <br><br> $Obit4"; if($Obit5 == "") print ""; if($Obit5 != "") print "<br><br>$Obit5"; if($Obit6 == "") print ""; if($Obit6 != "") print "<br><br>$Obit6"; if($Obit7 == "") print ""; if($Obit7 != "") print "<br><br>$Obit7"; if($Obit8 == "") print ""; if($Obit8 != "") print "<br><br>$Obit8"; print "</p></body></html>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149742 Share on other sites More sharing options...
btherl Posted December 21, 2010 Share Posted December 21, 2010 kclark, can I get one more data item from you please, the output of this: print "Number of results: $num_results<br>"; This can go just after $num_results is set. Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149743 Share on other sites More sharing options...
kclark Posted December 21, 2010 Author Share Posted December 21, 2010 Where do I put that? Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149744 Share on other sites More sharing options...
PFMaBiSmAd Posted December 21, 2010 Share Posted December 21, 2010 Since you are able to echo $row['ID'] and get a value, that means that $row does contain an array (at some point in time.) Either - A) Your page or just that code is being requested/included twice and the second time there is no $_GET['ID'] present and the query matches zero rows, or B) extract() does not like the numeric/associative array that mysql_fetch_array() returns. You can try mysql_fetch_assoc() or why not just use the $row['name'] variables and forget about using extract(). Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149747 Share on other sites More sharing options...
kclark Posted December 21, 2010 Author Share Posted December 21, 2010 tried mysql_fetch_assoc() same error. How do I do $row['name'] ? Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149755 Share on other sites More sharing options...
Pikachu2000 Posted December 21, 2010 Share Posted December 21, 2010 Let's see exactly what the $row array contains. $result = mysql_query($query) or die("Couldn't execute query."); $row = mysql_fetch_array($result); // Add the following three lines as shown. echo '<pre>'; print_r($row); echo '</pre>'; //extract($row);This is the line that is giving me problems Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149758 Share on other sites More sharing options...
kclark Posted December 21, 2010 Author Share Posted December 21, 2010 I get an empty array. If I use my short query, I get the array. Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149898 Share on other sites More sharing options...
PFMaBiSmAd Posted December 21, 2010 Share Posted December 21, 2010 Did you ever successfully execute the long query directly using phpmyadmin, with an id value that does not work using php? At this point, I would say your problem is - When you join tables together using "INNER JOIN", results will only exist if there is data in ALL joined tables. If any table has the data missing, you will get nothing. Perhaps you have some white-space/non-printing characters in some of the data in the columns you are joining on and those columns don't match each other exactly. Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1149902 Share on other sites More sharing options...
kclark Posted December 21, 2010 Author Share Posted December 21, 2010 Okay I figured out what was going on. When I enter a record, I have 3 events that could happen. If 1 of the 3 doesn't happen, I enter No event which is = 0 in the places db table. If I put a number greater than 0 it works. How do I make it right then. Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1150047 Share on other sites More sharing options...
kclark Posted December 21, 2010 Author Share Posted December 21, 2010 Nevermind, somehow my None=0 got changed to 92. So for those with 0 in the table field it was kicking those out. and pulling my hair out. Thanks for everyone's help. Quote Link to comment https://forums.phpfreaks.com/topic/222218-php-array-stopped-working/#findComment-1150056 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.