通过php脚本插入50条记录


Insert 50 records through php script

我一次通过php脚本插入50条记录到数据库中。但是插入时会跳过2-3条记录。有什么问题吗?

请帮忙!

我猜LIMIT有问题。请检查任何人,并让我知道!

代码如下:

<?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);


}
?>

由于没有转义任何输入字符串,因此很有可能在某些表(可能是属性名)中使用撇号(')或任何其他受限制的字符,从而阻止您插入特定查询。例如,如果city为Campbell's Bay,则不首先转义撇号就不会插入。

使用mysql_real_escape_string


不要使用mysql_函数,因为它们已被弃用,使用mysqli_*代替*

可能在插入查询中出现错误打印sql代码并检查查询是否正确

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