0

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");
            }
        }
    }
4
Contributors
7
Replies
32
Views
2 Years
Discussion Span
Last Post by UK-1991
0

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.

Edited by pritaeas

0

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

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.

Edited by lorenzoDAlipio: corrected comments

0

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

0

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.

0

@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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.