Jump to content

vikrantmohite

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Posts posted by vikrantmohite

  1. I have a script with the code below that inserts a .csv file into a table, and had an issue where if no file is selected, it throws "fgetcsv() expects parameter 1 to be resource, boolean given" about 1,000,000 times or so until it fills up the error log and the hard drive.  I'm guessing someone probably has a simple solution on the below code on how to prevent that going forward, but I've just spent some time looking into it and haven't been able to find the solution.

     

    <?php
    
    $conn = mysql_connect("localhost", "dbuser", "dbpassword") or die(mysql_error());
    mysql_select_db("database") or die(mysql_error());
    
    // Delete existing values in test table before inserting updated file
    
    $sql_ini = "TRUNCATE table";
          mysql_query($sql_ini) or die(mysql_error());
    
    if(isset($_POST['SUBMIT']))
    {
    $file = $_FILES['file']['tmp_name'];
    
    $handle = fopen($file,"r");
    
    while(($fileop = fgetcsv($handle,1000,",")) != false)
    {
    	$field1 = $fileop[0];
    	$field2 = $fileop[1];
    	$field3 = $fileop[2];
    
    	// check for default values and delete locked row before inserting data
    
    	if (!empty($field1))
    	{
    	// Insert .csv file into database
    
    $sql = "INSERT INTO table (field1, field2, field3) values ('$field1', '$field2', '$field3')";
         mysql_query($sql) or die(mysql_error());
    		 }
    }
    if($sql)
       	{ 
       	// Show whether or not the file was added successfully:
       	
       echo "CSV file successfully imported.";
    
    } else {
    
    	echo "Data Insert Failed";
    }
    } 
    
    }
    
    ?>
    
    
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" enctype="multipart/form-data">
        <input type="file" name="file" />
        <br>
        <br>
        <input type="submit" name="SUBMIT" value="Submit" />
    </form>

     

    Thank you in advance for your assistance, and I appreciate your help. :)

     

    replace

    $handle = fopen($file,"r");
    

     

    with

    $handle = @fopen($file,"r");
    

     

    This will check whether the file can be read or not and allow further script to execute only if $handle is true.

     

    Hope this works for you.

  2. What exactly is the query? Since you are not escaping the data being put into it, it might have special sql characters that are breaking the sql syntax. Echo the $q variable and post the result.

     

    Is your query failing due to an error of some kind? For debugging purposes, change your mysql_query line of code to -

     

    mysql_query($q,$con) or die("Query failed: $q<br />Error: " . mysql_error($con));

     

    Thanks PFMaBiSmAd

     

    I got the solution

    I was getting a lot of white spaces while inserting data so data was not getting inserted into the table. I used trim() to remove white spaces and now everything is workin fine.

     

    Thanks to all for your support and response. :thumb-up:

  3. We need to see the code that you use for making the array, and the code for when you insert into the database table, else we can't really help.

     

    index.php

    <?php
    
        # don't forget the library
        include('simple_html_dom.php');
        
        # this is the global array we fill with article information
        $trains = array();
    
        # passing in the first page to parse, it will crawl to the end
        # on its own
        getArticles('http://www.makemytrip.com/railways/mumbai_sawantwadi_s-01013-train.html');
    
    
    
    
    
    
    function getArticles($page) {
    global $trains, $con;
        $html = new simple_html_dom();
        $html->load_file($page);
    
    $con = mysql_connect("localhost","root","");
    mysql_select_db("temp",$con);
    
    
    /*   foreach($html->find('table tr.segonroute1') as $e)
       {
    	//$details[] = $e->children(1)->outertext;
    	//echo $e->children(1)->outertext;
       }
    */   
       $route = $html->find('table tr.segonroute1');
       
       foreach($route as $key)
       	{
    	$trains[]=array(
    						$key->children(1)->plaintext,
    						$key->children(2)->plaintext,
    						$key->children(3)->plaintext,
    						$key->children(4)->plaintext,
    						$key->children(5)->plaintext,
    						$key->children(6)->plaintext
    					);
    
    //mysql_query("INSERT INTO trains (station_name, arrives, departs, halt_time, distance, train_no) VALUES ('".$key->children(1)->outertext."");
    
    }
    
    }
    
    
        foreach($trains as $item) {
            echo $item[0];
    	$s = (string) $item[0];
            echo " ".$item[1];
    	echo " ".$item[2];
    	echo " ".$item[3];
    	echo " ".$item[4];
    	echo " ".$item[5]."<br/>";
    
    
    	//mysql_query("INSERT INTO trains (station_name, arrives, departs, halt_time, distance, train_no) VALUES ('$item[0]','$item[1]','$item[2]','$item[3]','$item[5]',01013");
    	$q="INSERT INTO trains (station_name) VALUES ('$s')";
    	mysql_query($q,$con);
    
    
        }
    ?>
    
    

     

    simple_html_dom.php

    is attached here .

    18569_.php

  4. I am not able to insert data into table.

     

    I have some data in array.

     

    If I use echo array[index] I can see the data. But when I try to insert the data in database I am getting blank data in table.

     

    Can you please help me guys.

  5. Hi Experts,

     

    I am designing an application of bus reservation system.

     

    I am stuck with database design of the application.  Hope you people can help me on this.

     

    Each bus have unique ID (say BUS NO), source & destination.

     

    Now let say for

     

    Bus B123 source is A and destination is X and in between it stops at C,Z,N,H,K also.

    Bus B456 source is C and destination is Y and in between it stops at Z,N,K,P,Q,R,T,I,D also.

    Bus B789 source is G and destination is S and in between it stops at N,H,K,D,M also.

     

    Now if user search for bus from

    C to H it should give B123

    N to K it should give B123, B456, B789

    K to D it should give B456, B789

     

    Again if he search for Bus from

    H to C it should not give B123 (i.e the bus goes only from C to H and not from H to C)

     

    The fact that need to consider here is the sequence.

     

    I can't keep all stations in sequence as admin may want to update the route(adding or deletion of station) in future.

     

    I hope you have understood what I am planning to design. Please help me with this design.

     

    I have to create this design in MySQL.

     

    Please do reply if you don't understand the requirement or have any doubt.

     

    Looking forward for your valuable comments and suggestions

     

    Regards,

    Vikrant

     

    Note : Station names can be different for simplicity I have used alphabates. Stations don't follow any alphabetic order.

  6. form.php

    <form action='anotherPage.php' method='post>
         ...     form elements     ...
    
    </form>
    

     

    anotherPage.php

    <?php
    $_post['txtBox']  // collect info to send and do database insertion here
    
    ?>
    <html>
    
    ......... Some HTML Code..........
    
    </html>
    

  7. Hi,

     

    I want to generate a 10 digit PNR number in one of my application.  :)

     

    The PNR number to be generated should use the following :

     

    1. The name of the passenger(s).

    2. Contact details for the travel agent or airline office. (The minimum contact information enforced by CRS policy is typically the 8-digit IATA code of the travel agency or airline office, although there is usually at least one phone number as well, most often the agency phone number. Direct customer contact information is rarely required.)

    3. Ticketing details, either a ticket number or a ticketing time limit.

    4. Itinerary of at least one segment, which must be the same for all passengers listed.

    5. Name of the person providing the information. (This is usually entered in a "received from" field and recorded in the "history" or change log attached to the PNR, along with the user and office or agency ID of the airline or travel agency employee creating the PNR or entering the change. The "history" records the "received from" data separately for the initial creation of the PNR and for each subsequent change to it.)

     

    For better understanding of PNR follow http://en.wikipedia.org/wiki/Passenger_name_record

     

    I was planning to do MD5() on all the above fields but that will give me more than 10 letters(alphanumeric)

     

    Though it is mention in wiki that PNR can be Alphanumeric, I want to generate a Numeric PNR.  ;)

     

    Please help me on this.

     

    Regards,

    Vikrant

  8. Hi guys,

    I have stored some records in my table where table contains a column timestamp where I am storing a timestamp.

     

    I want to extract records for particular month with this timestamp.

     

    How I can write query for it??

  9. Are you using any framework or did you build app from scratch? It looks to me like CodeIgniter thats why i said to fix the link in JS.

     

    What is the name of class inside of admin/index.php controler?

     

     

    I am building application from scratch in MVC framework.  I am not using CodeIgniter. I am using controller admin.php.

     

    ..//application/controllers/admin.php

  10. The path for that controler function is admin/index/getCity. Change your javascript.

     

    Thanx for quick reply.

     

    I am using MVC So I have to call a function in controller which inturn receive data from model.

     

    admin is controller class and getCity is its method. getCity method calls model and receives data from it. So I dont think admin/index/getCity is going to work for me.

     

    mu Url is like localhost/application/controller/{method}/{arg if any} structure

  11. Please help me in this guys.......

    I am using MVC model for my application .

     

    I am stuck with the ajax call.

     

    this is my controller

    application/controller/admin/index.php

     

    function getCity()

      {

            $city=$this->model->getCity();

     

            foreach($this->city as $key => $value)

            {

                echo '<option>'.$value['name'].'</option>' ;

            }

      }

     

    this is my model

    application/model/admin_model.php

     

     

     

     

    public function getCity()

      {

          if($_POST['id'])

          {

          $cid=$_POST['id'];

          $sth = $this->db->prepare('SELECT id, name FROM unit WHERE cid= :cid');

          $sth->execute(array(':cid' => $cid));

          return $sth->fetchAll();

          }

      }

     

     

    this is my view

     

    <form id="city" action="<../application/admin/regstr/" method="post">

     

       

      Country

        <select name="country" class="country">

      <option value="" selected="selected">--Select Taluka--</option>

      <option value="1">India</option>

            <option value="2">USA</option>

      <option value="3">China</option>

        </select>

        City

        <select name="city" class="city">

      <option selected="selected">--Select City--</option>

       

        </select>

       

      <input type="submit" />

    </form>

     

     

    and this is my javascript for Ajax

     

    $(document).ready(function()

    {

     

      $(".country").change(function()

      {

          var id=$(this).val();

          var dataString = 'id='+ id;

     

          $.ajax

          ({

            type: "POST",

            url: "admin/getCity",

            data: dataString,

            cache: false,

            success: function(html)

            {

                $(".city").html(html);

            }

          });

     

      });

     

    });

     

     

     

    But I am not getting the output. I have tested it with firebug in response tab. Instead of getting only option values html code as output  I am getting the whole HTML page content (i.e. content of view page admin/index.php.

     

     

    Please help me out.

  12. Please help me in this guys.......

    I am using MVC model for my application .

     

    I am stuck with the ajax call.

     

    this is my controller

    application/controller/admin/index.php

     

    function getCity()

    {

    $city=$this->model->getCity();

     

    foreach($this->city as $key => $value)

    {

    echo '<option>'.$value['name'].'</option>' ;

    }

    }

     

    this is my model

    application/model/admin_model.php

     

     

     

     

    public function getCity()

    {

    if($_POST['id'])

    {

    $cid=$_POST['id'];

    $sth = $this->db->prepare('SELECT id, name FROM unit WHERE cid= :cid');

    $sth->execute(array(':cid' => $cid));

    return $sth->fetchAll();

    }

    }

     

     

    this is my view

     

    <form id="city" action="<../application/admin/regstr/" method="post">

     

       

      Country

        <select name="country" class="country">

    <option value="" selected="selected">--Select Taluka--</option>

    <option value="1">India</option>

            <option value="2">USA</option>

    <option value="3">China</option>

        </select>

        City

        <select name="city" class="city">

    <option selected="selected">--Select City--</option>

       

      </select>

       

    <input type="submit" />

    </form>

     

     

    and this is my javascript for Ajax

     

    $(document).ready(function()

    {

     

    $(".country").change(function()

    {

    var id=$(this).val();

    var dataString = 'id='+ id;

     

    $.ajax

    ({

    type: "POST",

    url: "admin/getCity",

    data: dataString,

    cache: false,

    success: function(html)

    {

    $(".city").html(html);

    }

    });

     

    });

     

    });

     

     

     

    But I am not getting the output. I have tested it with firebug in response tab. Instead of getting only option values html code as output  I am getting the whole HTML page content (i.e. content of view page admin/index.php.

     

     

    Please help me out.

  13. Are you asking how to implement your own translation service equivalent to the translation service created by a trillion-dollar company with more than 5,000 years of formal computer science education between its employees?  You absolutely cannot write your own version of google translated.  Never, ever.  Every single person on this message board, working together,  couldn't do it in less than a decade.  Google translate's algorithm is so incredible that it recently was able to automatically crack a secret document more than 150 years old.

     

    As depressing and annoying and the answer may be, it remains:  No, you can't do that.  You're not smart enough.  None of us are. 

     

    If you want to implement a translation service these are your options:

    1)  Purchase a dictionary application to do word-for-word translations, which are often incorrect.

    2)  Write your own word-for-word dictionary application.  This isn't incredibly difficult, but how do you do a proper translation of words with multiple meanings?  The English word "run" has nearly 400 official definitions.  Which Hindi word will you choose to represent it?

    3)  Run everything through google.

     

     

     

    How I can do it using google then?

  14. I want to do the translation like this

     

    http://translate.google.com/#en|hi|Hindi

     

    But I want to do it offline for my website on localhost. I do not want to connect to the internet for doing this.

     

    Help me to do this plzzzzz

     

    Thanx in advance

    to my knowledge, you do not need an internet connection on localhost, since it is using a directory on your machine to retrieve its files.

     

     

     

    can you describe in detail how I can do that

×
×
  • 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.