0

I'm inserting 50 records at once via a php script into the database. But it skips 2-3 records while inserting. What is the problem?

Please help!

I guess there is some problem in the LIMIT. Please check anyone, and let me know!

Below is the code:

<?php
include_once 'db.php';
$selTable = "select * from dump_hotelbasicinfo LIMIT 50";
$resultTable = mysql_query($selTable, $conn);
while($rowTable = mysql_fetch_array($resultTable))
{
    echo "<br> <strong> Hotel ID </strong>  : " .$rowTable['id'];
    echo "<br> <strong> Hotel Name  </strong>: " .$rowTable['HotelName'];
    echo "<br> <strong> Hotel Code  </strong>: " .$rowTable['HotelCode'];
    echo "<br> <strong> Chain Code  </strong>: " .$rowTable['ChainCode'];
    echo "<br> <strong> Hotel Type  </strong>: " .$rowTable['HotelType'];
    echo "<br> <strong> Hotel Category  </strong>: " .$rowTable['HotelCategory'];
    echo "<br> <strong> Hotel Style  </strong>: " .$rowTable['HotelStyle'];
    echo "<br> <strong> Hotel Theme  </strong>: " .$rowTable['HotelTheme'];
    echo "<br> <strong> Rating  </strong>: " .$rowTable['StarRating'];
    echo "<br> <strong> Destination Name  </strong>: " .$rowTable['DestinationName'];
    echo "<br> <strong> Country Name  </strong>: " .$rowTable['CountryName'];   
    echo "<br> <strong> Hotel Info  </strong>: " .$rowTable['HotelInfo'];
    echo "<br> <strong> Number of Floors  </strong>: " .$rowTable['NumFloors'];
    echo "<br> <strong> Number of Rooms  </strong>: " .$rowTable['NoOfRooms'];
    echo "<br> <strong> DateTime  </strong>: " .$rowTable['datetimespan'];

    echo "<hr>";

$sqlInsert="INSERT INTO `hotel_info` 
                            (`property_name` , 
                             `property_town` ,
                             `property_country` , 
                             `property_description`, 
                             `published` , 
                             `stars` , 
                             `ptype_id` , 
                             `last_changed`
                             ) 
               VALUES
                       ('$rowTable[HotelName]' , '$rowTable[DestinationName]' , '$rowTable[CountryName]', ' $rowTable[HotelInfo]','1' ,
                       '$rowTable[StarRating]' , '1','$rowTable[datetimespan]')";
                       //echo $sqlInsert;
                       //exit();

    $resultInsert = mysql_query($sqlInsert);




}
?>
jarlh
  • 42,561
  • 8
  • 45
  • 63
  • Try to count your query result by doing this: `$selTable = "select count(*) from dump_hotelbasicinfo LIMIT 50";` and avoid the use of `mysql_*` – Indrasinh Bihola Aug 17 '15 at 10:29
  • you **must** refactor to use `mysqli`. The `mysql` driver is deprecated and no longer supported. Have a look [here](http://stackoverflow.com/questions/3536103/mysql-how-many-rows-can-i-insert-in-one-single-insert-statement) for a possible solution to your actual issue. – DevDonkey Aug 17 '15 at 10:29
  • Can you also add info/structure of "hotel_info" table? Probably here is problems with duplicate records and as result - they aren't inserted in DB. – Vladimir Gilevich Aug 17 '15 at 10:30
  • Is it possible that you have ' signs or / inside some of names you insert? Since you are using old mysql_* functions it might be escape string fail on insert. – Nightwhistle Aug 17 '15 at 10:31
  • Post your data as well – amit Aug 17 '15 at 10:32
  • We are not here to do your assignments. – Indrasinh Bihola Aug 17 '15 at 10:49

2 Answers2

0

Probably you have an error in insert query print the sql code and check which the query is correct.

//...
echo $sqlInsert;
 //exit();
0

Since you are not escaping any input strings, it is highly possible that you have apostrophes (') or any other restricted character in some tables (probably property name) that prevents you from inserting that specific query. In example, if city is Campbell's Bay it wont be inserted without escaping apostrophe first.

use mysql_real_escape_string


Do not use mysql_ functions as they are being deprecated, use mysqli_* instead*

Nightwhistle
  • 197
  • 1
  • 11