Hello,

I created a query insert query everything is in right order but dont know whyy its not working

function submit_report() {
        global $connection;

        if(isset($_POST["submit"])) {
            $id       = 215;
            $name     = "myname";
            $uname    = "myusername";
            $date     = $_POST['date'];
            $campaign = $_POST['campaign'];
            $t_leads  = $_POST['t_leads'];
            $c_leads  = $_POST['c_leads'];
            $open_acc = $_POST['open_acc'];
            $n_sure   = $_POST['n_sure'];
            $l_upload = $_POST['l_upload'];
            $dreport  = $_POST['dreport'];
            $reason   = $_POST['reason'];
            $comments = $_POST['comments'];
            //
            $insert  = "INSERT INTO status_report (user_id, fullname, user_name, campaign, date, tleads, cleads, op_acc, nsure, lupload, fdelivered, reason, comments)";
            $insert .= " VALUES ('$id', '$name', '$uname', '$campaign', '$date', '$t_leads', '$c_leads', '$open_acc', '$n_sure', '$l_upload', '$dreport', '$reason', '$comments')";
            //

            $insert_query = mysqli_query($connection, $insert);

            if(confirm_query($insert_query)) {
                $_SESSION["message"] = "Your report have been submitted successfully";
                redirect_to("home.php");
            } else {
                $_SESSION["message"] = "There were some errors please re submit your report";
                redirect_to("submit_rep.php");
            }
        }
    }

dont know whyy its not working

What is not working? What did you expect to happen, and what didn't?

If it's the query, I suggest you add error checking.

Okay this is the confirm query

function confirm_query($result_output) {
        if (!$result_output) {
            die ("Database Query Failed");
        }
    }

the main problem is very starnge though the data is inserting into the database but the code is not executinf if statmement its directly jumping to the elase statement by viewing the code you will also notice that everything is in right order though

if(confirm_query($insert_query)) {//checking this its true 
  $_SESSION["message"] = "Your report have been submitted successfully";//not entring if block
                redirect_to("home.php");
            } else {
 $_SESSION["message"] = "There were some errors please re submit your //jumped directly to this block report";
                redirect_to("submit_rep.php");
            }

you should add

return true;

somewhere in your confirm_query() function, preferrably after the die() function and then you can evaluate like this

if(confirm_query($insert_query)){
        /* you won't pass this point if it is false right? */

        /* do whatever you have to do */

}

relying on die() function is a poor choice though. Not saying that you are wrong, but there are other options.

Well totally agreed with your pint but the its not false as by viewing you will also notice that this tatememnt is coming up true is'nt it

if you are confident with you codes, then just leave it like that and wait for someone to help you maybe they can do better.. :). Just my humble opinion.

@lorenzoDAlipio I am really sorry as you are senior than me my motive was not that though as not confident as well bus just was asking about it my appology

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.