Category Archives: PHP

Invalid argument supplied for foreach in mysqli.php on line 391

This is a note to self.  When you see Warning: Invalid argument supplied for foreach() in /home/yourdom/public_html/libraries/joomla/database/database/mysqli.php on line 391 it means the host has run out of disk space on the tmp folder used for sessions and other temporary files.  Specifically Joomla is trying to create a temporary table and it appears it gets as far as creating the pointer and php/mysql errors at the point of reading the data rather than at the point of adding data to the table.

So if you are not me and you have this error then the solution is to ask your host to clear out the /tmp folder and increase the amount of disk space allocated to it so it doesn’t happen again.

Repairing MySQL Databases with PHP

The following PHP code repairs databases that show an overhead. Remove the errorlog function if not required.

<?php
$sql = "SHOW TABLE STATUS";
$result = mysql_query($sql) or errorlog( __LINE__."\n\n".mysql_error()."\n\n$sql");
if($result && mysql_num_rows($result)) {
  while($row = mysql_fetch_assoc($result)) {
    if($row['Data_free'] > 0) {
      $sql = "REPAIR TABLE ".$row['Name'].";";
      $repair = mysql_query($sql) or errorlog( __LINE__."\n\n".mysql_error()."\n\n$sql");		
      if($repair) {
        echo "<br /><em>".$row['Name']." succesfully repaired</em>";
      } else {
        echo "<br /><strong>".$row['Name']." error: ".mysql_error()."</strong>";
      }
    }
  }	
}
 
//Stub
function errorlog($msg) { echo $msg; }
 
?>

Using twitter as an alerting platform

mypph 300x228 Using twitter as an alerting platformI received an email from Clickatell inviting me to top up my SMS account.  After a split second consideration I realised I did not need them anymore.  Sorry Clickatell!

Twitter is more convenient.  I have set up a few private accounts and subscribed to them through my own.  When an event occurs I receive notification direct to my phone as a free SMS message direct from twitter.

Although twitter has been unreliable lately it has proven more convenient than using Clickatell.  In time twitter will fix the problems and they may even be suitable for mission critical solutions.  I hope so because they are easy to use and should spawn many superb product ideas all designed to keep us informed with the information we want now, not just when we visit facebook.




Payment Processing for Onelogbook

homepage 150x150 Payment Processing for OnelogbookOnelogbook is an outdoor sports activity program currently in development. My task was to add Paypal payment processing to the joining form.

Technologies used were PHP, MySQL, Javascript and I created a few minor graphics. Payment information is sent to Paypal for processing. On successful payment Paypal return IPN (Instant Payment Notification) code to the website and the user is authorised to use the website extended features.

Javascript is used for form validation and PHP provides the server side code. If a payment is cancelled user details are removed from memory and the database is not updated (you can see the cancellation notice at the end of this short high speed video).

And a “Please Wait” graphic – scourge of Paypal Payment Processing!

pleasewait Payment Processing for Onelogbook