script regarding IMAP(need help)

hanwei

New member
Joined
Dec 3, 2006
Messages
1
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? im new to php and imap and i do not know how imap works..

oh, and by the way. is there any command which will allow us to check what linux OS we using? im a newbie ^^'''...


thanks in advance.. :D
PHP:
<?
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);

}
?>
 
I'm not sure why you'd expect us to debug your programming for you.

The DirectAdmin forums exist for the purpose of helping owners and users of the DirectAdmin hosting control panel learn about DA and how to use it.

There's no way you can tell which OS is being used from the DirectAdmin control panel.

If you own your own copy of DirectAdmin then you should know what OS you had installed on the server. if you don't own your own copy of DirectAdmin then you should probably ask your hosting company.

Jeff
 
Back
Top