Jump to content

script regarding IMAP..(please help to check)


hanwei

Recommended Posts

Hi, can anyone tell me whether the format of my script is correct or wrong? i'm now planning how my imap script looks like and i need some idea... thanks.

the purpose of this script is to grab data from email and inserted into my database(this is only the planning)..
the $From, $Message in my insert statement(bottom) is declared above...

I think the declaration and the grab mail is wrong. And by the way, do i have to install IMAP inorder to use it?

[code]<?
include "staff-auth.php";

$link = mysql_connect("127.0.0.1", "mysql") or die("Could not connect: " . mysql_error());
mysql_select_db("ttmodule", $link) or die("Unable to select database: . mysql_error()");



<--------------- place where i insert the command to grab data from mail ------------------->
$mbox = imap_open ("{localhost:143/notls}Inbox", $username, $password) or die("can't connect: " . imap_last_error());

$From=imap_fetchheader ($mbox, "From:");
$Message = imap_fetchheader ($mbox, "Message:");






$selectSql= "SELECT * FROM ttcounter ";
$result = mysql_query($selectSql, $link);
$row = mysql_fetch_array($result);
$tt_No = $row["lastnumber"] + 1;

$updateSql = "UPDATE ttcounter set lastnumber = '$tt_No' ";
mysql_query($updateSql)
or die("Error in query $updateSql " . mysql_error());




$getIndexVarSql= "SELECT * FROM ttmvariables ";
$result = mysql_query($getIndexVarSql, $link);
$row = mysql_fetch_array($result);
$primary = $row["primaryIndex"];
$secondary = $row["secondaryIndex"];

$remainderPri = $tt_No % $primary;
$quotientPri = ($tt_No - ($tt_No % $primary)) / $primary;

if ($remainderPri == "1") {
$newIndexPriNo = ($quotientPri + 1) * $primary;
$newIndexSecTbl = "indexsec" . ($quotientPri + 1);
$insPriRecSql = "INSERT INTO indexpri ".
    "(indexPriNo, indexSecTbl) VALUES ".
    "('$newIndexPriNo', '$newIndexSecTbl') ";
mysql_query($insPriRecSql) or die("Error in query $insPriRecSql " . mysql_error());
$newSecTblSql = "CREATE TABLE $newIndexSecTbl ".
"(indexSecNo INT UNSIGNED, ".
"mainTbl VARCHAR(20), ".
"PRIMARY KEY(indexSecNo)) ";
mysql_query($newSecTblSql) or die("Error in query $newSecTblSql " . mysql_error());

$newIndexSecNo = ($newIndexPriNo - $primary) + $secondary;
$ttMainTbl = $newIndexSecTbl . "main1";
$insSecRecSql = "INSERT INTO $newIndexSecTbl ".
    "(indexSecNo, mainTbl) VALUES ".
    "('$newIndexSecNo', '$ttMainTbl') ";
mysql_query($insSecRecSql) or die("Error in query $insSecRecSql " . mysql_error());
$newMainTblSql = "CREATE TABLE $ttMainTbl (".
"ttNo INT UNSIGNED, ttTicketRef VARCHAR(90), ttCompany VARCHAR(90), ttCompCat VARCHAR(30), ".
"ttClientName VARCHAR(90), ttClientEmail VARCHAR(90), ttProbDesc LONGTEXT, ttNewTime TIMESTAMP, ".
"ttResTime TIMESTAMP, ttEsclTime INT(10) UNSIGNED, ttServices VARCHAR(40), ttStatus VARCHAR(30), ".
"ttPriority VARCHAR(30), ttNature VARCHAR(30), ttEngrAsgn VARCHAR(20), ttEngrEscl VARCHAR(20), ttSubmitBy VARCHAR(30), ".
"PRIMARY KEY (ttNo)) ";
mysql_query($newMainTblSql) or die("Error in query $newMainTblSql " . mysql_error());
}
else {
$getSecTblSql = "SELECT * FROM indexpri WHERE indexPriNo IN (SELECT MAX(indexPriNo) FROM indexpri) ";
$sqlResult = mysql_query($getSecTblSql, $link);
$row = mysql_fetch_array($sqlResult);
$usePriNo = $row["indexPriNo"];
$useSecTbl = $row["indexSecTbl"];

$remainderSec = $remainderPri % $secondary;
$quotientSec = ($remainderPri - ($remainderPri % $secondary)) / $secondary;

if ($remainderSec == "1") {
$newIndexSecNo = ($usePriNo - $primary) + (($quotientSec + 1) * $secondary);
$ttMainTbl = $useSecTbl . "main" . ($quotientSec + 1);
$insSecRecSql = "INSERT INTO $useSecTbl ".
    "(indexSecNo, mainTbl) VALUES ".
    "('$newIndexSecNo', '$ttMainTbl') ";
mysql_query($insSecRecSql) or die("Error in query $insSecRecSql " . mysql_error());
$newMainTblSql = "CREATE TABLE $ttMainTbl (".
"ttNo INT UNSIGNED, ttTicketRef VARCHAR(90), ttCompany VARCHAR(90), ttCompCat VARCHAR(30), ".
"ttClientName VARCHAR(90), ttClientEmail VARCHAR(90), ttProbDesc LONGTEXT, ttNewTime TIMESTAMP, ".
"ttResTime TIMESTAMP, ttEsclTime varchar(90), ttServices VARCHAR(30), ttStatus VARCHAR(30), ".
"ttPriority VARCHAR(30), ttNature VARCHAR(30), ttEngrAsgn VARCHAR(20), ttEngrEscl VARCHAR(20), ttSubmitBy VARCHAR(30), ".
"PRIMARY KEY (ttNo)) ";
mysql_query($newMainTblSql) or die("Error in query $newMainTblSql " . mysql_error());
}
else {
$getMainTblSql = "SELECT mainTbl FROM $useSecTbl WHERE indexSecNo IN (SELECT MAX(indexSecNo) FROM $useSecTbl) ";
$sqlResult = mysql_query($getMainTblSql, $link);
$row = mysql_fetch_array($sqlResult);
$ttMainTbl = $row["mainTbl"];
}
}



<--------------------------------place where i do a insert command to insert the data into my database---------------------->


$insertSql = "INSERT INTO $ttMainTbl ".
"(ttNo, ttTicketRef, ttCompany, ttCompCat, ttClientName, ttClientEmail, ttProbDesc, ttNewTime, ttResTime, ".
"ttEsclTime, ttServices, ttStatus, ttPriority, ttNature, ttEngrAsgn, ttEngrEscl, ttSubmitBy) VALUES ".
"(null,null,null,null,null, '$From', '$Message', NOW(), ".
"'', '',null,null, '',null, '', '',null) ";
mysql_query($insertSql) or die("Error in query $insertSql " . mysql_error());
}


mysql_close($link);

}
?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.