| medvirus |
10-12-2010 04:24 PM |
hi i made one script but it is very long , i wan a short script
i m posting that script here ::
sql database file
Code:
-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Sep 29, 2010 at 06:37 AM
-- Server version: 5.1.36
-- PHP Version: 5.3.0
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: `sms`
--
-- --------------------------------------------------------
--
-- Table structure for table `sms`
--
CREATE TABLE IF NOT EXISTS `sms` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`num` varchar(50) NOT NULL,
`dir` varchar(20) NOT NULL DEFAULT '',
`time` varchar(20) NOT NULL DEFAULT '',
`date` varchar(20) NOT NULL DEFAULT '',
`month` varchar(20) NOT NULL DEFAULT '',
`yr` varchar(20) NOT NULL DEFAULT '',
`sms` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `sms`
--
-- --------------------------------------------------------
--
-- Table structure for table `td`
--
CREATE TABLE IF NOT EXISTS `td` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`td` text NOT NULL,
`tsms` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `td`
--
===============
this is index.php
PHP Code:
<?php
session_start();
//connection
$db_host = "localhost";
//database username
$db_username = "";
//database password
$db_password = "";
//database name
$db_name = "sms";
mysql_connect($db_host,$db_username,$db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
include "../style1.php";
//open file by selected txt
$file = fopen("file.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
echo"<div bgcolor=#660099><h1>SMS From $msg</h1></div>";
echo"<table><tr bgcolor=#FF6633>
<td>No</td>
<td>Specific</td>
<td>SMS</td>
</tr>";
$i=1 ;
$k=1 ;
$l=1 ;
$m=1 ;
while(!feof($file))
{$sms=fgets($file);
$detail=explode(" ", $sms);
$string=$detail['0'].$detail[1];
$sl=strlen($string);
if($sl=='18' OR $sl=='17'){
$d=$sms;
$d = stripslashes($d);
$d= trim($d);
$d = mysql_real_escape_string($d);
mysql_query("INSERT INTO td (td) VALUES('$d')") or die (mysql_error());
echo "<tr bgcolor=#FFCC99>
<td><font color=#000000>$i</font></td>
<td><font color=#FFFFFF>$k</font></td>
<td><font color=#000000>$d(<b>Added</b>) <b>$sl</b></font></td>
</tr>";
$k++;
}
else if($sl>2)
{
$d=$sms;
$d = stripslashes($d);
$d= trim($d);
$d = mysql_real_escape_string($d);
$sql = "SELECT id FROM td ORDER BY id DESC LIMIT 0,1";
$s= mysql_query($sql)or die (mysql_error());
$x = mysql_fetch_array($s);
$id1=$x['id'];
$insertlink="UPDATE td SET tsms='$d' WHERE id='$id1'";
mysql_query($insertlink) or die(mysql_error());
echo "<tr bgcolor=#0066FF>
<td><font color=#000000>$i</font></td>
<td><font color=#FFFFFF>$l</font></td>
<td><font color=black>$d(<b>Added</b>) <b>$sl</b></font></td>
</tr>";
$l++;
}
else {
echo "<tr bgcolor=#FF0000>
<td><font color=#00CC33>$i</font></td>
<td><font color=#FFFFFF>$m</font></td>
<td><font color=#330033>Not Added $sl</font></td>
</tr>
<tr bgcolor=#FFFFFF><td></td><td></td><td><b><h3>Blank</h3></b></td></tr>";
$m++;
}
$i++;
} fclose($file);
echo"</table>";
echo"</table>
<div align=center><a href=import.php><h1>Import Above FIle</h1></a></div>
";
echo"<form action=\"importfinal.php\" method=\"POST\">";
echo"<b>Do you Want to Empty Td 9Tempory Detail table from SMS database</b><br/>
<input type=\"submit\" name=\"empty\" class=input value=\"Empty td\" id=\"empty\">|
<a href=index.php>No(Home)</a></form>";
//Complete ftext
?>
=============
importfinal.php
=========
PHP Code:
<?php
session_start();
//connection
$db_host = "localhost";
//database username
$db_username = "";
//database password
$db_password = "";
//database name
$db_name = "sms";
mysql_connect($db_host,$db_username,$db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
include "../style1.php";
if(isset($_POST['import']))
{
$query = "SELECT * FROM td ORDER BY id";
$result = mysql_query($query) or die(mysql_error());
$i=1;
while($r = mysql_fetch_array($result)) {
$id = $r['id'];
$td = $r['td'];
$tsms = $r['tsms'];
$url=array("$td", "$tsms");
$sms=implode("/",$url);
$contain = explode("/", $sms,2);
$fpart=$contain[0];
$detail=explode(" ", $fpart);
$datet=$detail[0];
$timep=$detail[1];
$ampm=$detail[2];
$sname=$detail[4];
$date = explode("-", $datet);
$day=$date[0];
$month=$date[1];
$yr= $date[2];
$time1 = explode(":", $timep);
$hh1=$time1[0];
$mm=$time1[1];
if($ampm=='pm'){
if($hh1=='12'){$hh=$hh1;}else{$hh=$hh1+12 ;}
;}
else if($ampm=='am'){
if($hh1=='12'){$hh='00';}else{$hh=$hh1;}
;}
if($sname=='myself'){
$dir=2;
$col="#FF9966";
$name='Me';
$num='9998968730';
}
else{
$dir=1;
$col="#3366CC";
$name1=explode("(", $sname);
$name=$name1[0];
$num = substr($name1[1], 3,10);
};
$msgs=$contain['1'];
$msgs = stripslashes($msgs);
$msgs= trim($msgs);
$msgs = mysql_real_escape_string($msgs);
$time="$hh:$mm";
mysql_query("INSERT INTO sms (name,num, dir, time, date, month,yr,sms) VALUES('$name','$num', '$dir','$time', '$day', '$month', '$yr', '$msgs')") or die (mysql_error());
$i++;
}
$count=$i-1;
echo "<h1>[$count] Imported Succesfully</h1>";
echo"<form action=\"importfinal.php\" method=\"POST\">";
echo"<b>Do you Want to Empty Td 9Tempory Detail table from SMS database</b><br/>
<input type=\"submit\" name=\"empty\" class=input value=\"Empty td\" id=\"empty\">|
<a href=index.php>No(Home)</a></form>";
}
if(isset($_POST['empty']))
{
mysql_query("TRUNCATE `td`") or die (mysql_error());
$query = "SELECT * FROM td ORDER BY id";
$count = mysql_query($query) or die(mysql_error());
$total = mysql_num_rows($count);
if (empty($total)) {
echo "<div class=d align=\"left\" ><b><font color=\"#CC0000\">Deleted TD Table</font></b><br/>
<a href=index.php>Go to Home</a></div>";
}
else { echo "$total Row Present"; }
}
?>
===========
import.php
===========
PHP Code:
<?php
session_start();
//connection
$db_host = "localhost";
//database username
$db_username = "";
//database password
$db_password = "";
//database name
$db_name = "sms";
mysql_connect($db_host,$db_username,$db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
include "../style1.php";
echo"<div bgcolor=#660099><h1>SMS View</h1></div>";
echo"<table><tr bgcolor=#FF6633>
<td>No</td> <td>Date</td>
<td>SMS</td>
<td>Status</td>
</tr>";
$query = "SELECT * FROM td ORDER BY id";
$result = mysql_query($query) or die(mysql_error());
echo"<form action=\"importfinal.php\" method=\"POST\">";
$i=1;
while($r = mysql_fetch_array($result)) {
$id = $r['id'];
$td = $r['td'];
$tsms = $r['tsms'];
$url=array("$td", "$tsms");
$sms=implode("/",$url);
$contain = explode("/", $sms,2);
$fpart=$contain[0];
$detail=explode(" ", $fpart);
$datet=$detail[0];
$timep=$detail[1];
$ampm=$detail[2];
$sname=$detail[4];
$date = explode("-", $datet);
$day=$date[0];
$month=$date[1];
$yr= $date[2];
$time1 = explode(":", $timep);
$hh1=$time1[0];
$mm=$time1[1];
if($ampm=='pm'){
if($hh1=='12'){$hh=$hh1;}else{$hh=$hh1+12 ;}
;}
else if($ampm=='am'){
if($hh1=='12'){$hh='00';}else{$hh=$hh1;}
;}
if($sname=='myself'){
$dir=2;
$col="#FF9966";
$name='Me';
$num='9998968730';
}
else{
$dir=1;
$col="#3366CC";
$name1=explode("(", $sname);
$name=$name1[0];
$num = substr($name1[1], 3,10);
};
$msgs=$contain['1'];
$msgs = stripslashes($msgs);
$msgs= trim($msgs);
$msgs = mysql_real_escape_string($msgs);
$time="$hh:$mm";
echo " <tr bgcolor=$col><td>$i</td>
<td>$day/$month/$yr</td>
<td><font color=white><b>($time)</b></font>$msgs</td>
<td><font color=white>Waiting</font></td>
</tr>";
$i++;
}
echo"<tr align=center class=row_f><td></td><td></td><td>
<input type=\"submit\" name=\"import\" class=input value=\"Import\" id=\"import\"></td>";
print "</tr></table>";
?>
=============================
Now you can see how much long code i have to write ,and some timeit not import correct...
|