If anyone's interested, here's my code. I've tested it briefly and it works perfectly so far. Hope it's bug free, but would appreciate any feedback if it is not
** I made a php file. Fill in the parameters as shown
newposting.php?key=1234567890&uid=2&sub=TestXYZ&cat=3&txt=TESTxyz
** Here's the code
<?php
//Only allow if correct key
if ($_GET["key"] != "1234567890")
{
echo "Wrong key!";
exit;
}
//Parameters
$user_id = $_GET["uid"];
$subject = $_GET["sub"];
$category = $_GET["cat"];
$text = $_GET["txt"];
$uniqid = genRandomString(); //Is this necessary
//Insert in DB
include('config/db_settings.php');
$link = mysql_connect($db_settings['host'], $db_settings['user'], $db_settings['password']);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$result = mysql_query("SELECT id FROM MyDB.mlf2_entries ORDER BY id DESC LIMIT 0,1");
$largestID = mysql_result($result, 0);
$id = $largestID + 1;
$pid = 0;
$tid = $id;
mysql_query("INSERT INTO MyDB.mlf2_entries (id, pid, tid, uniqid, user_id, subject, category, text) VALUES ($id, '$pid', '$tid', '$uniqid', '$user_id', '$subject', '$category', '$text')");
$result = mysql_query("SELECT time FROM MyDB.mlf2_entries WHERE id = $id");
$last_reply = mysql_result($result, 0);
mysql_query("UPDATE MyDB.mlf2_entries SET last_reply ='$last_reply' WHERE id = $id");
mysql_close($link);
echo "Inserted successfully";
function genRandomString() {
$length = 13;
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$string = '';
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string;
}
?>