mySQL查询执行但不插入数据

时间:2013-09-01 03:59:02

标签: php mysql

我正在尝试从PHP代码中将数据插入到mySQL查询中。代码执行时没有任何错误,但不会将数据插入数据库。可能有什么不对?提前谢谢。

    <?php 
    include 'dbc.php';
    $sql="INSERT INTO `realtorl_leads`.`data` (`LeadFirstName`, `LeadLastName`, `LeadEmail`, `LeadEmail2`, `LeadPhone`, `LeadCity`, `LeadAddress`, `LeadPostcode`, `LeadUserId`, `LeadLeadStatusId`, `LeadMonth`, `LeadAreas`, `LeadMinPrice`, `LeadMaxPrice`, `LeadMinBedrooms`, `LeadMaxBedrooms`, `LeadMinBathrooms`, `LeadMaxBathrooms`, `LeadMinYear`, `LeadNextFollowup_mm`, `LeadNextFollowup_dd`, `LeadNextFollowup`) VALUES ('Fahad', 'Uddin', 'fahad.fu@gmail,com', 'fahad@ff.com', '3242342', 'karachi', '3234asdasd.karachi', '74600', '222', '32432', '23', '232', '232', '23', '232', '323', '323', '232', '23232', '3232', '232', '23232')";
    ?>

编辑:

我现在有以下代码,执行的代码只显示一个新的行和文本说它不起作用。请指导。

<?php 
include 'dbc.php';
$LeadFirstName = $_POST['LeadFirstName'];
$LeadFirstName = $_POST['LeadFirstName'];
$LeadEmail =$_POST['LeadEmail'];
$LeadEmail2 =$_POST['LeadEmail2'];
$LeadPhone =$_POST['LeadPhone'];
$LeadCity =$_POST['LeadCity'];
$LeadAddress =$_POST['LeadAddress'];
$LeadPostcode =$_POST['LeadPostcode'];
$LeadUserId =$_POST['LeadUserId'];
$LeadLeadStatusId =$_POST['LeadLeadStatusId'];
$LeadMonth =$_POST['LeadMonth'];
$LeadAreas =$_POST['LeadAreas'];
$LeadMinPrice =$_POST['LeadMinPrice'];
$LeadMaxPrice =$_POST['LeadMaxPrice'];
$LeadMinBedrooms =$_POST['LeadMinBedrooms'];
$LeadMaxBedrooms =$_POST['LeadMaxBedrooms'];
$LeadMinBathrooms =$_POST['LeadMinBathrooms'];
$LeadMaxBathrooms =$_POST['LeadMaxBathrooms'];
$LeadMinYear =$_POST['LeadMinYear'];
$LeadNextFollowup_mm =$_POST['LeadNextFollowup_mm'];
$LeadNextFollowup_dd =$_POST['LeadNextFollowup_dd'];
$LeadNextFollowup =$_POST['LeadNextFollowup'];
$sql="INSERT INTO 'realtorl_leads'.`data (`LeadFirstName`, `LeadLastName`, `LeadEmail`, `LeadEmail2`, `LeadPhone`, `LeadCity`, `LeadAddress`, `LeadPostcode`, `LeadUserId`, `LeadLeadStatusId`, `LeadMonth`, `LeadAreas`, `LeadMinPrice`, `LeadMaxPrice`, `LeadMinBedrooms`, `LeadMaxBedrooms`, `LeadMinBathrooms`, `LeadMaxBathrooms`, `LeadMinYear`, `LeadNextFollowup_mm`, `LeadNextFollowup_dd`, `LeadNextFollowup`) VALUES ($LeadFirstName, $LeadLastName, $LeadEmail, $LeadEmail2, $LeadPhone, $LeadCity, $LeadAddress, $LeadPostcode, $LeadUserId, $LeadLeadStatusId, $LeadMonth, $LeadAreas, $LeadMinPrice, $LeadMaxPrice, $LeadMinBedrooms, $LeadMaxBedrooms, $LeadNextFollowup_mm, $LeadNextFollowup_dd, $LeadNextFollowup)";
$result = mysql_query($sql);
echo($result."<br>");
if (mysql_affected_rows($result)){
  echo("worked");
}else {
  echo("does not work");
}
?>

2 个答案:

答案 0 :(得分:1)

您需要执行查询

include 'dbc.php';
$sql="INSERT INTO `realtorl_leads`.`data` (`LeadFirstName`, `LeadLastName`, `LeadEmail`, `LeadEmail2`, `LeadPhone`, `LeadCity`, `LeadAddress`, `LeadPostcode`, `LeadUserId`, `LeadLeadStatusId`, `LeadMonth`, `LeadAreas`, `LeadMinPrice`, `LeadMaxPrice`, `LeadMinBedrooms`, `LeadMaxBedrooms`, `LeadMinBathrooms`, `LeadMaxBathrooms`, `LeadMinYear`, `LeadNextFollowup_mm`, `LeadNextFollowup_dd`, `LeadNextFollowup`) VALUES ('Fahad', 'Uddin', 'fahad.fu@gmail,com', 'fahad@ff.com', '3242342', 'karachi', '3234asdasd.karachi', '74600', '222', '32432', '23', '232', '232', '23', '232', '323', '323', '232', '23232', '3232', '232', '23232')";
mysqli_query($con, $sql);
?>

答案 1 :(得分:1)

您的代码缺少部分,请尝试:

include 'dbc.php';
$sql="INSERT INTO `realtorl_leads`.`data` (`LeadFirstName`, `LeadLastName`, `LeadEmail`, `LeadEmail2`, `LeadPhone`, `LeadCity`, `LeadAddress`, `LeadPostcode`, `LeadUserId`, `LeadLeadStatusId`, `LeadMonth`, `LeadAreas`, `LeadMinPrice`, `LeadMaxPrice`, `LeadMinBedrooms`, `LeadMaxBedrooms`, `LeadMinBathrooms`, `LeadMaxBathrooms`, `LeadMinYear`, `LeadNextFollowup_mm`, `LeadNextFollowup_dd`, `LeadNextFollowup`) VALUES ('Fahad', 'Uddin', 'fahad.fu@gmail,com', 'fahad@ff.com', '3242342', 'karachi', '3234asdasd.karachi', '74600', '222', '32432', '23', '232', '232', '23', '232', '323', '323', '232', '23232', '3232', '232', '23232')";
$result = mysql_query($sql);

使用$result检查命令是否正在执行,尝试执行此操作:

if (mysql_num_rows($result)){
  //echo successfull execution message
}else {

  //echo error message, it could be "information is not added"
}

尽管mysql已经过折旧但它仍适用于我。