user379888
user379888

Reputation:

mySQL query executes but does not insert the data

I am trying to insert data into mySQL query from PHP code. The code executes without any error but does not insert the data into the database. What could be wrong? Thanks in advance.

    <?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 ('x', 'y', '[email protected]', '[email protected]', '3242342', 'karachi', '3234asdasd.karachi', '74600', '222', '32432', '23', '232', '232', '23', '232', '323', '323', '232', '23232', '3232', '232', '23232')";
    ?>

EDIT:

I have the following code now, the executed code just shows a new line and text saying it does not work. Please guide.

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

Upvotes: 0

Views: 181

Answers (2)

Nouman
Nouman

Reputation: 45

Your code has a part missing, try:

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', '[email protected]', '3242342', 'karachi', '3234asdasd.karachi', '74600', '222', '32432', '23', '232', '232', '23', '232', '323', '323', '232', '23232', '3232', '232', '23232')";
$result = mysql_query($sql);

use $result to check whether your command is executing successfully, to do this try:

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

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

though mysql is depreciated but it still works for me.

Upvotes: 1

DevZer0
DevZer0

Reputation: 13525

you will need to execute the query

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', '[email protected]', '3242342', 'karachi', '3234asdasd.karachi', '74600', '222', '32432', '23', '232', '232', '23', '232', '323', '323', '232', '23232', '3232', '232', '23232')";
mysqli_query($con, $sql);
?>

Upvotes: 1

Related Questions