Leave a reply

Using post requests in WordPress

I recently created a simple form in PHP which acts as kind of contact form in order to send mails after a successfull request.
I run into trouble when submitting the form: I always got redirected to a 404 site, although the url itself was correct.

The sample looks like this:


// send mail


<form action=”” method=”post”>
<p><label>Name: </label><input name=”name” type=”text” /></p>
<p><label>E-Mail: </label><input name=”mail” type=”email” /></p>
<input type=”submit” name=”send” value=”Contact”</form>

I found out that the reason was that the field name “name” is reserved by wordpress. After renaming it to e.g. “name2” the 404 error was gone.

Leave a reply

Importing large SQL exports into mySQL

This solution is for a problem I run across while trying to import a sql-export file which was about 2 GB in size. phpMyAdmin usually fails when the filesizes get to big, and using the HTTP POST method is not a good idea for such huge amounts of data anyway. So I decided to go along with php.

  1. Create a folder on your webspace
  2. Upload the sql file to your webspace (e.g. via FTP)
  3. Create a php in the same folder
  4. Put the following content into it:

// Name of the file
$filename = ‘export.sql’;
// MySQL host
$mysql_host = ‘your.host.com’;
// MySQL username
$mysql_username = ‘db_user’;
// MySQL password
$mysql_password = ‘db_pass’;
// Database name
$mysql_database = ‘db_name’;

mysql_connect($mysql_host, $mysql_username, $mysql_password) or die(‘Error connecting to MySQL server: ‘ . mysql_error());
// Select database
mysql_select_db($mysql_database) or die(‘Error selecting MySQL database: ‘ . mysql_error());

// Temporary variable, used to store current query
$templine = ”;
// Get file handle
$file = fopen($filename,”r”);
// Loop through each line
while ($file && !feof($file))
// Skip it if it’s a comment
if (substr($line, 0, 2) == ‘–‘ || $line == ”)

// Add this line to the current segment
$templine .= $line;
// If it has a semicolon at the end, it’s the end of the query
if (substr(trim($line), -1, 1) == ‘;’)
// Perform the query
mysql_query($templine) or print(‘Error performing query \'<strong>’ . $templine . ‘\’: ‘ . mysql_error() . ‘<br /><br />’);
// Reset temp variable to empty
echo “added entry\n”;
$templine = ”;
echo “Tables imported successfully”;

Note that the file will loop through each line. Using file() or file_get_contents() will fail because you will get an out-of-memory error. Besides this seems to be slow, it’s still performing quite well even for large files.

Leave a reply

Delete old attachments from OSTicket

A problem I recently encountered was that the OSTicket mySQL Database get’s huge (more than 1 Gigabyte) if you receive a lot of mails with big attachments.

I decided to delete older attachment-data. Below is a php script you can put on your server inside a folder like “delete_attachment”. This folder must be at the location of your OSTicket installation.

include_once dirname(__FILE__).”/../main.inc.php”;
$res = db_query (‘DELETE FROM ost_file_chunk WHERE file_id IN

If you don’t want to create a php script, you can also run a sql query via phpMyAdmin:

DELETE FROM ost_file_chunk WHERE file_id IN (SELECT id FROM ost_file WHERE created < DATE_SUB(NOW(), INTERVAL 60 DAY)

Replace 60 with whatever number of days you want to keep attachments.