mysql select query running okay on phpmyadmin but not with php [closed]












1















This is the mysql query



SELECT *,
`main`.`email` as useremail,
`main`.`ID` as `userID`,
`mail_owners`.`country_code_field` as `micountry`,
DATE(`main`.`time`) as `mrDate`
FROM `main`
LEFT JOIN `mail_owners`
ON `main`.`ID` = `mail_owners`.`ID`
WHERE
`main`.`is_deleted` = 0 AND
(`main`.`time` BETWEEN '2018-08-01' AND '2018-11-14')
ORDER BY
`main`.`ID`,
`mrDate` DESC


This query working perfectly on sql....but it's not working perfectly on php.
it's running on php but only getting some data not the total.



here describes the php codes:



$fdt = $_POST['formDt'];
$tdt = $_POST['toDate'];

$sqlforData = "SELECT *, `main`.`email` as useremail, `main`.`ID` as `userID`, `mail_owners`.`country_code_field` as `micountry`, DATE(`main`.`time`) as `mrDate` FROM `main` LEFT JOIN `mail_owners` ON `main`.`ID` = `mail_owners`.`ID` WHERE `main`.`is_deleted` = 0 AND (`main`.`time` BETWEEN '$fdt' AND '$tdt') ORDER BY `main`.`ID`, `mrDate` DESC";

$result = mysqli_query($conn, $sqlforData);
while ($table = mysqli_fetch_array($result)) {
//Showing just limited data...
}


Please help me to sort out the problem.



Thank you.










share|improve this question















closed as unclear what you're asking by peterh, yivi, Madhur Bhaiya, Machavity, Makyen Nov 24 '18 at 18:29


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 2





    You should include data which explains the problem. I don't think you will get an answer if both queries are identical.

    – Tim Biegeleisen
    Nov 24 '18 at 15:59











  • Warning: You are wide open to SQL Injections and should really use parameterized Prepared Statements instead of manually building your queries like that. Specially since you're not escaping the user inputs at all!

    – Magnus Eriksson
    Nov 24 '18 at 15:59






  • 2





    You should also do a var_dump($fdt, $tdt); to make sure they contain the same values as the hard coded one.

    – Magnus Eriksson
    Nov 24 '18 at 16:01






  • 1





    I don't see any error checking so no wonder you don't know why it's not working. Read this question and come back with the error message from MySQL

    – Machavity
    Nov 24 '18 at 17:16
















1















This is the mysql query



SELECT *,
`main`.`email` as useremail,
`main`.`ID` as `userID`,
`mail_owners`.`country_code_field` as `micountry`,
DATE(`main`.`time`) as `mrDate`
FROM `main`
LEFT JOIN `mail_owners`
ON `main`.`ID` = `mail_owners`.`ID`
WHERE
`main`.`is_deleted` = 0 AND
(`main`.`time` BETWEEN '2018-08-01' AND '2018-11-14')
ORDER BY
`main`.`ID`,
`mrDate` DESC


This query working perfectly on sql....but it's not working perfectly on php.
it's running on php but only getting some data not the total.



here describes the php codes:



$fdt = $_POST['formDt'];
$tdt = $_POST['toDate'];

$sqlforData = "SELECT *, `main`.`email` as useremail, `main`.`ID` as `userID`, `mail_owners`.`country_code_field` as `micountry`, DATE(`main`.`time`) as `mrDate` FROM `main` LEFT JOIN `mail_owners` ON `main`.`ID` = `mail_owners`.`ID` WHERE `main`.`is_deleted` = 0 AND (`main`.`time` BETWEEN '$fdt' AND '$tdt') ORDER BY `main`.`ID`, `mrDate` DESC";

$result = mysqli_query($conn, $sqlforData);
while ($table = mysqli_fetch_array($result)) {
//Showing just limited data...
}


Please help me to sort out the problem.



Thank you.










share|improve this question















closed as unclear what you're asking by peterh, yivi, Madhur Bhaiya, Machavity, Makyen Nov 24 '18 at 18:29


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 2





    You should include data which explains the problem. I don't think you will get an answer if both queries are identical.

    – Tim Biegeleisen
    Nov 24 '18 at 15:59











  • Warning: You are wide open to SQL Injections and should really use parameterized Prepared Statements instead of manually building your queries like that. Specially since you're not escaping the user inputs at all!

    – Magnus Eriksson
    Nov 24 '18 at 15:59






  • 2





    You should also do a var_dump($fdt, $tdt); to make sure they contain the same values as the hard coded one.

    – Magnus Eriksson
    Nov 24 '18 at 16:01






  • 1





    I don't see any error checking so no wonder you don't know why it's not working. Read this question and come back with the error message from MySQL

    – Machavity
    Nov 24 '18 at 17:16














1












1








1








This is the mysql query



SELECT *,
`main`.`email` as useremail,
`main`.`ID` as `userID`,
`mail_owners`.`country_code_field` as `micountry`,
DATE(`main`.`time`) as `mrDate`
FROM `main`
LEFT JOIN `mail_owners`
ON `main`.`ID` = `mail_owners`.`ID`
WHERE
`main`.`is_deleted` = 0 AND
(`main`.`time` BETWEEN '2018-08-01' AND '2018-11-14')
ORDER BY
`main`.`ID`,
`mrDate` DESC


This query working perfectly on sql....but it's not working perfectly on php.
it's running on php but only getting some data not the total.



here describes the php codes:



$fdt = $_POST['formDt'];
$tdt = $_POST['toDate'];

$sqlforData = "SELECT *, `main`.`email` as useremail, `main`.`ID` as `userID`, `mail_owners`.`country_code_field` as `micountry`, DATE(`main`.`time`) as `mrDate` FROM `main` LEFT JOIN `mail_owners` ON `main`.`ID` = `mail_owners`.`ID` WHERE `main`.`is_deleted` = 0 AND (`main`.`time` BETWEEN '$fdt' AND '$tdt') ORDER BY `main`.`ID`, `mrDate` DESC";

$result = mysqli_query($conn, $sqlforData);
while ($table = mysqli_fetch_array($result)) {
//Showing just limited data...
}


Please help me to sort out the problem.



Thank you.










share|improve this question
















This is the mysql query



SELECT *,
`main`.`email` as useremail,
`main`.`ID` as `userID`,
`mail_owners`.`country_code_field` as `micountry`,
DATE(`main`.`time`) as `mrDate`
FROM `main`
LEFT JOIN `mail_owners`
ON `main`.`ID` = `mail_owners`.`ID`
WHERE
`main`.`is_deleted` = 0 AND
(`main`.`time` BETWEEN '2018-08-01' AND '2018-11-14')
ORDER BY
`main`.`ID`,
`mrDate` DESC


This query working perfectly on sql....but it's not working perfectly on php.
it's running on php but only getting some data not the total.



here describes the php codes:



$fdt = $_POST['formDt'];
$tdt = $_POST['toDate'];

$sqlforData = "SELECT *, `main`.`email` as useremail, `main`.`ID` as `userID`, `mail_owners`.`country_code_field` as `micountry`, DATE(`main`.`time`) as `mrDate` FROM `main` LEFT JOIN `mail_owners` ON `main`.`ID` = `mail_owners`.`ID` WHERE `main`.`is_deleted` = 0 AND (`main`.`time` BETWEEN '$fdt' AND '$tdt') ORDER BY `main`.`ID`, `mrDate` DESC";

$result = mysqli_query($conn, $sqlforData);
while ($table = mysqli_fetch_array($result)) {
//Showing just limited data...
}


Please help me to sort out the problem.



Thank you.







php mysql sql database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 15:58









Tim Biegeleisen

229k1395147




229k1395147










asked Nov 24 '18 at 15:56









M.i. SujonM.i. Sujon

1125




1125




closed as unclear what you're asking by peterh, yivi, Madhur Bhaiya, Machavity, Makyen Nov 24 '18 at 18:29


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as unclear what you're asking by peterh, yivi, Madhur Bhaiya, Machavity, Makyen Nov 24 '18 at 18:29


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 2





    You should include data which explains the problem. I don't think you will get an answer if both queries are identical.

    – Tim Biegeleisen
    Nov 24 '18 at 15:59











  • Warning: You are wide open to SQL Injections and should really use parameterized Prepared Statements instead of manually building your queries like that. Specially since you're not escaping the user inputs at all!

    – Magnus Eriksson
    Nov 24 '18 at 15:59






  • 2





    You should also do a var_dump($fdt, $tdt); to make sure they contain the same values as the hard coded one.

    – Magnus Eriksson
    Nov 24 '18 at 16:01






  • 1





    I don't see any error checking so no wonder you don't know why it's not working. Read this question and come back with the error message from MySQL

    – Machavity
    Nov 24 '18 at 17:16














  • 2





    You should include data which explains the problem. I don't think you will get an answer if both queries are identical.

    – Tim Biegeleisen
    Nov 24 '18 at 15:59











  • Warning: You are wide open to SQL Injections and should really use parameterized Prepared Statements instead of manually building your queries like that. Specially since you're not escaping the user inputs at all!

    – Magnus Eriksson
    Nov 24 '18 at 15:59






  • 2





    You should also do a var_dump($fdt, $tdt); to make sure they contain the same values as the hard coded one.

    – Magnus Eriksson
    Nov 24 '18 at 16:01






  • 1





    I don't see any error checking so no wonder you don't know why it's not working. Read this question and come back with the error message from MySQL

    – Machavity
    Nov 24 '18 at 17:16








2




2





You should include data which explains the problem. I don't think you will get an answer if both queries are identical.

– Tim Biegeleisen
Nov 24 '18 at 15:59





You should include data which explains the problem. I don't think you will get an answer if both queries are identical.

– Tim Biegeleisen
Nov 24 '18 at 15:59













Warning: You are wide open to SQL Injections and should really use parameterized Prepared Statements instead of manually building your queries like that. Specially since you're not escaping the user inputs at all!

– Magnus Eriksson
Nov 24 '18 at 15:59





Warning: You are wide open to SQL Injections and should really use parameterized Prepared Statements instead of manually building your queries like that. Specially since you're not escaping the user inputs at all!

– Magnus Eriksson
Nov 24 '18 at 15:59




2




2





You should also do a var_dump($fdt, $tdt); to make sure they contain the same values as the hard coded one.

– Magnus Eriksson
Nov 24 '18 at 16:01





You should also do a var_dump($fdt, $tdt); to make sure they contain the same values as the hard coded one.

– Magnus Eriksson
Nov 24 '18 at 16:01




1




1





I don't see any error checking so no wonder you don't know why it's not working. Read this question and come back with the error message from MySQL

– Machavity
Nov 24 '18 at 17:16





I don't see any error checking so no wonder you don't know why it's not working. Read this question and come back with the error message from MySQL

– Machavity
Nov 24 '18 at 17:16












1 Answer
1






active

oldest

votes


















0














could be you have some quote and conversion issue try using str_to_date and for avoid sqlinject and comversion problem to try using prepared statement and binding param eg:



    $sqlforData = "SELECT *
, `main`.`email` as useremail
, `main`.`ID` as `userID`
, `mail_owners`.`country_code_field` as `micountry`
, DATE(`main`.`time`) as `mrDate`
FROM `main`
LEFT JOIN `mail_owners` ON `main`.`ID` = `mail_owners`.`ID`
WHERE `main`.`is_deleted` = 0 AND (`main`.`time` BETWEEN STR_TO_DATE(?, '%Y-%m%d')
AND STR_TO_DATE(?, '%Y-%m%d'))
ORDER BY `main`.`ID`, `mrDate` DESC";


$stmt = $mysqli->prepare($sqlforData);
$stmt->bind_param('ss', $fdt, $tdt, );

$stmt->execute();





share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    could be you have some quote and conversion issue try using str_to_date and for avoid sqlinject and comversion problem to try using prepared statement and binding param eg:



        $sqlforData = "SELECT *
    , `main`.`email` as useremail
    , `main`.`ID` as `userID`
    , `mail_owners`.`country_code_field` as `micountry`
    , DATE(`main`.`time`) as `mrDate`
    FROM `main`
    LEFT JOIN `mail_owners` ON `main`.`ID` = `mail_owners`.`ID`
    WHERE `main`.`is_deleted` = 0 AND (`main`.`time` BETWEEN STR_TO_DATE(?, '%Y-%m%d')
    AND STR_TO_DATE(?, '%Y-%m%d'))
    ORDER BY `main`.`ID`, `mrDate` DESC";


    $stmt = $mysqli->prepare($sqlforData);
    $stmt->bind_param('ss', $fdt, $tdt, );

    $stmt->execute();





    share|improve this answer




























      0














      could be you have some quote and conversion issue try using str_to_date and for avoid sqlinject and comversion problem to try using prepared statement and binding param eg:



          $sqlforData = "SELECT *
      , `main`.`email` as useremail
      , `main`.`ID` as `userID`
      , `mail_owners`.`country_code_field` as `micountry`
      , DATE(`main`.`time`) as `mrDate`
      FROM `main`
      LEFT JOIN `mail_owners` ON `main`.`ID` = `mail_owners`.`ID`
      WHERE `main`.`is_deleted` = 0 AND (`main`.`time` BETWEEN STR_TO_DATE(?, '%Y-%m%d')
      AND STR_TO_DATE(?, '%Y-%m%d'))
      ORDER BY `main`.`ID`, `mrDate` DESC";


      $stmt = $mysqli->prepare($sqlforData);
      $stmt->bind_param('ss', $fdt, $tdt, );

      $stmt->execute();





      share|improve this answer


























        0












        0








        0







        could be you have some quote and conversion issue try using str_to_date and for avoid sqlinject and comversion problem to try using prepared statement and binding param eg:



            $sqlforData = "SELECT *
        , `main`.`email` as useremail
        , `main`.`ID` as `userID`
        , `mail_owners`.`country_code_field` as `micountry`
        , DATE(`main`.`time`) as `mrDate`
        FROM `main`
        LEFT JOIN `mail_owners` ON `main`.`ID` = `mail_owners`.`ID`
        WHERE `main`.`is_deleted` = 0 AND (`main`.`time` BETWEEN STR_TO_DATE(?, '%Y-%m%d')
        AND STR_TO_DATE(?, '%Y-%m%d'))
        ORDER BY `main`.`ID`, `mrDate` DESC";


        $stmt = $mysqli->prepare($sqlforData);
        $stmt->bind_param('ss', $fdt, $tdt, );

        $stmt->execute();





        share|improve this answer













        could be you have some quote and conversion issue try using str_to_date and for avoid sqlinject and comversion problem to try using prepared statement and binding param eg:



            $sqlforData = "SELECT *
        , `main`.`email` as useremail
        , `main`.`ID` as `userID`
        , `mail_owners`.`country_code_field` as `micountry`
        , DATE(`main`.`time`) as `mrDate`
        FROM `main`
        LEFT JOIN `mail_owners` ON `main`.`ID` = `mail_owners`.`ID`
        WHERE `main`.`is_deleted` = 0 AND (`main`.`time` BETWEEN STR_TO_DATE(?, '%Y-%m%d')
        AND STR_TO_DATE(?, '%Y-%m%d'))
        ORDER BY `main`.`ID`, `mrDate` DESC";


        $stmt = $mysqli->prepare($sqlforData);
        $stmt->bind_param('ss', $fdt, $tdt, );

        $stmt->execute();






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 16:23









        scaisEdgescaisEdge

        95.4k105071




        95.4k105071

















            Popular posts from this blog

            To store a contact into the json file from server.js file using a class in NodeJS

            Redirect URL with Chrome Remote Debugging Android Devices

            Dieringhausen