TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-08-2010, 08:05 PM   #1 (permalink)
The Wanderer
 
Join Date: Oct 2010
Posts: 9
Thanks: 2
medvirus is on a distinguished road
Default Help for import data from txt file

hi
Friend,
i have a one txt file , which data i have to extract and put in mysql database with php
sow you here and i m showing u a how i put data in mysql

TXt file data


Code:
                                                                     
                                                                     
                                                                     
                                             


============================================================
============================================================

25-09-2010 8:41:39 pm Sat ABC(+919800000000)
Rat gai ne savar padi gai.

Wah wah

rat gai ne savar padi gai.

Wah wah.

Daya- Acp game te hoy tamara to mathe taal padi gai....

25-09-2010 8:57:27 pm Sat ABC(+919800000000))
GOLU: Gandhiji K sir par Baal Q Nai the?

Teacher: Intelligent admi ki nishani Hai..

GOLU:Tabhi Ladkiyo k itne Lambe Baal hote Hai..

25-09-2010 9:41:51 pm Sat ABC(+919800000000)
SARDAR became TRAIN DRIVER.

The 1st Train Driven by him was 5 Hrs late

Why?


Coz he stopd at evry Fatak & ask.
"MUMBAI javu hoy to sidhu j javanu ne.,?

25-09-2010 11:44:27 pm Sat ABC(+919800000000)
Kon kahe 6 k ame radta ta...

Aeto ame ansuo thi ankho dhota ta


i have to make 7 table in database like
HTML Code:
<table><tr>
<td>id</td>
<td>date</td>
<td>month</td>
<td>year</td>
<td>time</td>
<td>sender</td>
<td>number</td>
<td>sms</td>
</tr>
><tr>
<td>1</td>
<td>25</td>
<td>9</td>
<td>2010</td>
<td>8:41</td>
<td>ABC</td>
<td>9800000000</td>
<td> Rat gai ne savar padi gai.Wah wahrat gai ne savar padi gai.Wah wah.Daya- Acp game te hoy tamara to  </td>
</tr>
><tr>
<td>2</td>
<td>25</td>
<td>9</td>
<td>2010</td>
<td>8:57</td>
<td>ABC</td>
<td>9800000000</td>
<td> GOLU: Gandhiji K sir par Baal Q Nai the? 
Teacher: Intelligent admi ki nishani Hai..
GOLU:Tabhi Ladkiyo k itne Lambe Baal hote Hai..</td>
</tr>
</TABLE>
etc ....like many message i have in file

so can you do this ..
medvirus is offline  
Reply With Quote
Old 10-11-2010, 07:39 PM   #2 (permalink)
The Wanderer
 
Join Date: Oct 2010
Posts: 9
Thanks: 2
medvirus is on a distinguished road
Default

Is nobody can help me on this topic????
medvirus is offline  
Reply With Quote
Old 10-12-2010, 03:18 PM   #3 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

What attempts thus far have you made to do this? Can you post your code?
__________________
My Blog
Enfernikus is offline  
Reply With Quote
Old 10-12-2010, 04:24 PM   #4 (permalink)
The Wanderer
 
Join Date: Oct 2010
Posts: 9
Thanks: 2
medvirus is on a distinguished road
Default

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=;
                
$k=;
                
$l=;
                
$m=;
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...
medvirus is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Venerable methods and the applications they are commonly trusted in. Village Idiot Tips & Tricks 7 11-06-2008 07:36 AM
Aptana Jaxer and file uploads xenon Advanced PHP Programming 2 06-06-2008 10:22 AM
external data into a text file Seraskier Advanced PHP Programming 7 04-20-2008 05:04 AM
Writing to XML file buildakicker General 8 02-06-2008 08:17 PM
Tips: PHP security Village Idiot Tips & Tricks 22 11-23-2007 11:17 PM


All times are GMT. The time now is 09:03 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design