PDA

View Full Version : Joomla is failing on me!



CaldwellYSR
07-06-2011, 04:28 PM
So I've run into a problem with Joomla! I've posted on the joomla forums but nobody seems to answer me and I've gotten good responses from here before so hopefully someone can help me.

The problem is when I go to add any new content to the back-end of my joomla site, I can't do it. At the top of the page I'm getting three warnings that look like:



Warning: Invalid argument supplied for foreach() in /Applications/XAMPP/xamppfiles/htdocs/libraries/joomla/database/database/mysqli.php on line 727

Warning: Invalid argument supplied for foreach() in /Applications/XAMPP/xamppfiles/htdocs/libraries/joomla/database/database/mysqli.php on line 727

Warning: Invalid argument supplied for foreach() in /Applications/XAMPP/xamppfiles/htdocs/libraries/joomla/database/database/mysqli.php on line 727


So if I go to line 727 of the file it's giving me it says:



/**
* Retrieves information about the given tables
*
* @param array|string A table name or a list of table names
* @param boolean Only return field types, default true
* @return array An array of fields by table
*/
public function getTableFields($tables, $typeonly = true)
{
settype($tables, 'array'); //force to array
$result = array();

foreach ($tables as $tblval) {
$this->setQuery('SHOW FIELDS FROM ' . $tblval);
$fields = $this->loadObjectList();

if ($typeonly) {
foreach ($fields as $field) {
$result[$tblval][$field->Field] = preg_replace("/[(0-9)]/",'', $field->Type);
}
} else {
foreach ($fields as $field) {
$result[$tblval][$field->Field] = $field;
}
}
}

return $result;
}


I don't know enough php to completely understand this but it's the last foreach that is causing the problems. I THINK it has to do with getting the values from the boxes where I type in the article title and whatnot. I'm probably wrong though...

and then if I try to fill out the new article and save it despite the warnings it says:



Save failed with the following error: Please provide a valid, non-blank title.


This is the second time I've had this problem. The first time it happened I googled and googled to find the answer and for the first time in a long time google failed me. So I did a fresh install of xampp and joomla! and made the sit again and now the same problem has come up. This is my first site building my own theme instead of just using the themes given to me by default. It's getting quite frustrating to tell my friend that her site is ready to go just to tell her it's broken again. I'm doing all of this locally on my computer for now, I was planning on putting the site online when we got everything finalized. Any help fixing this would be appreciated so that I can get my first real website online.

dekan
07-07-2011, 05:44 PM
have you tried to do a var_dump( $tables ) right before foreach? Might help to know what exactly $tables is.

You don't check, if settype actually works for you. The function returns a bool, so I would change the code to:



if( settype($tables, 'array') )
{
//for testing:
var_dump( $tables );

$results = array();

foreach( ... )
{
...
}
}
else
{
//catch in case $tables cannot be set to array
...
}


Hope that helps!

CaldwellYSR
07-07-2011, 06:15 PM
I so wish that made sense... I don't know enough php to understand a word you're saying. That php came strait from the joomla mysqli.php file.

dekan
07-08-2011, 01:46 PM
I guess a php class is in order for you? :-)

When did the problem start coming up? Did you modify any code anywhere or installed additional modules?

foreach expects an array, the function before (settype) is supposed to force the $table parameter into an array. But this function can fail too and in order to test this, settype returns a boolean. In your case I suspect that $tables is something that cannot be forced to an array (maybe it's even null) and foreach gets a type it cannot deal with. Hence my suggestions above.

Having said that: I didn't know the code you posted is actually Joomla core code. Usually you wouldn't want to mess around in there to make things work. Next time you'd upgrade your system all those core files get replaced and your changes are gone.

In that case I'd start further back and would check which of the changes you had recently made is calling this function and what type the first parameter is. Make sure it's an array.

I guess that's all help I can provide without actually having a look at the system :-)

CaldwellYSR
07-11-2011, 07:42 PM
Thanks for the help! I haven't changed any core things but I'll go check out the extensions to see what could be causing the problems