PHP query wont insert to database











up vote
0
down vote

favorite
1












The below query wont insert to database, I had tried this query on my database so I am quite sure that the query is working. I also added the dbcon.php below.



<?php
require '../api/dbcon.php';

$stmt=$conn->prepare("INSERT INTO joborder (AirCondition,
CarpentryMasonry,
ElectricalWorks,
Plumbing,
Welding,
Campus,
priorityId,
RequestorName,
UserJobDescription,
SerialCode
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" );

$stmt->bind_param('ssssssssss',
$airConditioning,
$masonryCarpentry,
$electrical,
$plumbing,
$welding,
$campus,
$priority,
$requester,
$userJobDescription,
$serialCode);

$airConditioning = "check";
$masonryCarpentry = "check";
$electrical = "check";
$plumbing = "check";
$welding = "check";
$campus = 'NA';
$priority = '1';
$requester = "m";
$userJobDescription ="test";
//create serial code
$serialCode= "na12321";

?>


dbcon.php



      <?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbtable = "table";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbtable);

if(!$conn ){
die('Could not connect: ' . mysqli_error());
}
?>









share|improve this question




















  • 3




    You never execute the query? You should use $stmt->execute()
    – rpm192
    Nov 11 at 10:25










  • yah bro I forgot about that, I am not using php that much and dont know how to debug here. thanks for your comment :)
    – Night's Watch
    Nov 11 at 10:41

















up vote
0
down vote

favorite
1












The below query wont insert to database, I had tried this query on my database so I am quite sure that the query is working. I also added the dbcon.php below.



<?php
require '../api/dbcon.php';

$stmt=$conn->prepare("INSERT INTO joborder (AirCondition,
CarpentryMasonry,
ElectricalWorks,
Plumbing,
Welding,
Campus,
priorityId,
RequestorName,
UserJobDescription,
SerialCode
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" );

$stmt->bind_param('ssssssssss',
$airConditioning,
$masonryCarpentry,
$electrical,
$plumbing,
$welding,
$campus,
$priority,
$requester,
$userJobDescription,
$serialCode);

$airConditioning = "check";
$masonryCarpentry = "check";
$electrical = "check";
$plumbing = "check";
$welding = "check";
$campus = 'NA';
$priority = '1';
$requester = "m";
$userJobDescription ="test";
//create serial code
$serialCode= "na12321";

?>


dbcon.php



      <?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbtable = "table";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbtable);

if(!$conn ){
die('Could not connect: ' . mysqli_error());
}
?>









share|improve this question




















  • 3




    You never execute the query? You should use $stmt->execute()
    – rpm192
    Nov 11 at 10:25










  • yah bro I forgot about that, I am not using php that much and dont know how to debug here. thanks for your comment :)
    – Night's Watch
    Nov 11 at 10:41















up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





The below query wont insert to database, I had tried this query on my database so I am quite sure that the query is working. I also added the dbcon.php below.



<?php
require '../api/dbcon.php';

$stmt=$conn->prepare("INSERT INTO joborder (AirCondition,
CarpentryMasonry,
ElectricalWorks,
Plumbing,
Welding,
Campus,
priorityId,
RequestorName,
UserJobDescription,
SerialCode
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" );

$stmt->bind_param('ssssssssss',
$airConditioning,
$masonryCarpentry,
$electrical,
$plumbing,
$welding,
$campus,
$priority,
$requester,
$userJobDescription,
$serialCode);

$airConditioning = "check";
$masonryCarpentry = "check";
$electrical = "check";
$plumbing = "check";
$welding = "check";
$campus = 'NA';
$priority = '1';
$requester = "m";
$userJobDescription ="test";
//create serial code
$serialCode= "na12321";

?>


dbcon.php



      <?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbtable = "table";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbtable);

if(!$conn ){
die('Could not connect: ' . mysqli_error());
}
?>









share|improve this question















The below query wont insert to database, I had tried this query on my database so I am quite sure that the query is working. I also added the dbcon.php below.



<?php
require '../api/dbcon.php';

$stmt=$conn->prepare("INSERT INTO joborder (AirCondition,
CarpentryMasonry,
ElectricalWorks,
Plumbing,
Welding,
Campus,
priorityId,
RequestorName,
UserJobDescription,
SerialCode
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" );

$stmt->bind_param('ssssssssss',
$airConditioning,
$masonryCarpentry,
$electrical,
$plumbing,
$welding,
$campus,
$priority,
$requester,
$userJobDescription,
$serialCode);

$airConditioning = "check";
$masonryCarpentry = "check";
$electrical = "check";
$plumbing = "check";
$welding = "check";
$campus = 'NA';
$priority = '1';
$requester = "m";
$userJobDescription ="test";
//create serial code
$serialCode= "na12321";

?>


dbcon.php



      <?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbtable = "table";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbtable);

if(!$conn ){
die('Could not connect: ' . mysqli_error());
}
?>






php mysqli






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 2:39









Isaac Bennetch

7,67621629




7,67621629










asked Nov 11 at 10:22









Night's Watch

31




31








  • 3




    You never execute the query? You should use $stmt->execute()
    – rpm192
    Nov 11 at 10:25










  • yah bro I forgot about that, I am not using php that much and dont know how to debug here. thanks for your comment :)
    – Night's Watch
    Nov 11 at 10:41
















  • 3




    You never execute the query? You should use $stmt->execute()
    – rpm192
    Nov 11 at 10:25










  • yah bro I forgot about that, I am not using php that much and dont know how to debug here. thanks for your comment :)
    – Night's Watch
    Nov 11 at 10:41










3




3




You never execute the query? You should use $stmt->execute()
– rpm192
Nov 11 at 10:25




You never execute the query? You should use $stmt->execute()
– rpm192
Nov 11 at 10:25












yah bro I forgot about that, I am not using php that much and dont know how to debug here. thanks for your comment :)
– Night's Watch
Nov 11 at 10:41






yah bro I forgot about that, I am not using php that much and dont know how to debug here. thanks for your comment :)
– Night's Watch
Nov 11 at 10:41














2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










you're using a bad error reporting mode, and thus need to meticulously check for errors everywhere, but you're not.



on not-dbcon.php on line 4 you're not checking that $conn->prepare succeeded, do that, it returns bool(false) if there was an error. on line 16 you're not checking that $stmt->bind_param succeeded, do that, it returns bool(false) if there was an error. or better yet, don't do that, just convert return-value-error-reporting into exception-error-reporting, by running $conn->report_mode = MYSQLI_REPORT_ALL; immediately after creating the object.



... and most importantly, seems you forgot to run $stmt->execute(), which actually executes the query, which obviously explains why you're not inserting anything.






share|improve this answer






























    up vote
    0
    down vote













    <?php

    $servername = "localhost";
    $username = "root";
    $password = "123456";
    $database = "inventory";
    // Create connection
    $conn = new mysqli($servername, $username, $password, $database);

    $stat = $conn->prepare("INSERT INTO salary (name, salary, job) values (?, ?, ?)");

    $name = 'test';
    $salary = '21123';
    $job = 'demo';

    $stat->bind_param($name,$salary, $job );

    // Check connection
    if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    }

    // prepare and bind
    $stmt = $conn->prepare("INSERT INTO salary (name, salary, job) VALUES (?, ?, ?)");
    $stmt->bind_param("sss", $firstname, $lastname, $email);

    // set parameters and execute
    $firstname = "Johnqqq";
    $lastname = "123123";
    $email = "sdadsad";
    $stmt->execute();

    echo "New records created successfully";

    $stmt->close();
    $conn->close();

    ?>





    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247783%2fphp-query-wont-insert-to-database%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote



      accepted










      you're using a bad error reporting mode, and thus need to meticulously check for errors everywhere, but you're not.



      on not-dbcon.php on line 4 you're not checking that $conn->prepare succeeded, do that, it returns bool(false) if there was an error. on line 16 you're not checking that $stmt->bind_param succeeded, do that, it returns bool(false) if there was an error. or better yet, don't do that, just convert return-value-error-reporting into exception-error-reporting, by running $conn->report_mode = MYSQLI_REPORT_ALL; immediately after creating the object.



      ... and most importantly, seems you forgot to run $stmt->execute(), which actually executes the query, which obviously explains why you're not inserting anything.






      share|improve this answer



























        up vote
        0
        down vote



        accepted










        you're using a bad error reporting mode, and thus need to meticulously check for errors everywhere, but you're not.



        on not-dbcon.php on line 4 you're not checking that $conn->prepare succeeded, do that, it returns bool(false) if there was an error. on line 16 you're not checking that $stmt->bind_param succeeded, do that, it returns bool(false) if there was an error. or better yet, don't do that, just convert return-value-error-reporting into exception-error-reporting, by running $conn->report_mode = MYSQLI_REPORT_ALL; immediately after creating the object.



        ... and most importantly, seems you forgot to run $stmt->execute(), which actually executes the query, which obviously explains why you're not inserting anything.






        share|improve this answer

























          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          you're using a bad error reporting mode, and thus need to meticulously check for errors everywhere, but you're not.



          on not-dbcon.php on line 4 you're not checking that $conn->prepare succeeded, do that, it returns bool(false) if there was an error. on line 16 you're not checking that $stmt->bind_param succeeded, do that, it returns bool(false) if there was an error. or better yet, don't do that, just convert return-value-error-reporting into exception-error-reporting, by running $conn->report_mode = MYSQLI_REPORT_ALL; immediately after creating the object.



          ... and most importantly, seems you forgot to run $stmt->execute(), which actually executes the query, which obviously explains why you're not inserting anything.






          share|improve this answer














          you're using a bad error reporting mode, and thus need to meticulously check for errors everywhere, but you're not.



          on not-dbcon.php on line 4 you're not checking that $conn->prepare succeeded, do that, it returns bool(false) if there was an error. on line 16 you're not checking that $stmt->bind_param succeeded, do that, it returns bool(false) if there was an error. or better yet, don't do that, just convert return-value-error-reporting into exception-error-reporting, by running $conn->report_mode = MYSQLI_REPORT_ALL; immediately after creating the object.



          ... and most importantly, seems you forgot to run $stmt->execute(), which actually executes the query, which obviously explains why you're not inserting anything.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 11 at 11:17









          Wai Ha Lee

          5,640123662




          5,640123662










          answered Nov 11 at 10:34









          hanshenrik

          9,16621537




          9,16621537
























              up vote
              0
              down vote













              <?php

              $servername = "localhost";
              $username = "root";
              $password = "123456";
              $database = "inventory";
              // Create connection
              $conn = new mysqli($servername, $username, $password, $database);

              $stat = $conn->prepare("INSERT INTO salary (name, salary, job) values (?, ?, ?)");

              $name = 'test';
              $salary = '21123';
              $job = 'demo';

              $stat->bind_param($name,$salary, $job );

              // Check connection
              if ($conn->connect_error) {
              die("Connection failed: " . $conn->connect_error);
              }

              // prepare and bind
              $stmt = $conn->prepare("INSERT INTO salary (name, salary, job) VALUES (?, ?, ?)");
              $stmt->bind_param("sss", $firstname, $lastname, $email);

              // set parameters and execute
              $firstname = "Johnqqq";
              $lastname = "123123";
              $email = "sdadsad";
              $stmt->execute();

              echo "New records created successfully";

              $stmt->close();
              $conn->close();

              ?>





              share|improve this answer

























                up vote
                0
                down vote













                <?php

                $servername = "localhost";
                $username = "root";
                $password = "123456";
                $database = "inventory";
                // Create connection
                $conn = new mysqli($servername, $username, $password, $database);

                $stat = $conn->prepare("INSERT INTO salary (name, salary, job) values (?, ?, ?)");

                $name = 'test';
                $salary = '21123';
                $job = 'demo';

                $stat->bind_param($name,$salary, $job );

                // Check connection
                if ($conn->connect_error) {
                die("Connection failed: " . $conn->connect_error);
                }

                // prepare and bind
                $stmt = $conn->prepare("INSERT INTO salary (name, salary, job) VALUES (?, ?, ?)");
                $stmt->bind_param("sss", $firstname, $lastname, $email);

                // set parameters and execute
                $firstname = "Johnqqq";
                $lastname = "123123";
                $email = "sdadsad";
                $stmt->execute();

                echo "New records created successfully";

                $stmt->close();
                $conn->close();

                ?>





                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  <?php

                  $servername = "localhost";
                  $username = "root";
                  $password = "123456";
                  $database = "inventory";
                  // Create connection
                  $conn = new mysqli($servername, $username, $password, $database);

                  $stat = $conn->prepare("INSERT INTO salary (name, salary, job) values (?, ?, ?)");

                  $name = 'test';
                  $salary = '21123';
                  $job = 'demo';

                  $stat->bind_param($name,$salary, $job );

                  // Check connection
                  if ($conn->connect_error) {
                  die("Connection failed: " . $conn->connect_error);
                  }

                  // prepare and bind
                  $stmt = $conn->prepare("INSERT INTO salary (name, salary, job) VALUES (?, ?, ?)");
                  $stmt->bind_param("sss", $firstname, $lastname, $email);

                  // set parameters and execute
                  $firstname = "Johnqqq";
                  $lastname = "123123";
                  $email = "sdadsad";
                  $stmt->execute();

                  echo "New records created successfully";

                  $stmt->close();
                  $conn->close();

                  ?>





                  share|improve this answer












                  <?php

                  $servername = "localhost";
                  $username = "root";
                  $password = "123456";
                  $database = "inventory";
                  // Create connection
                  $conn = new mysqli($servername, $username, $password, $database);

                  $stat = $conn->prepare("INSERT INTO salary (name, salary, job) values (?, ?, ?)");

                  $name = 'test';
                  $salary = '21123';
                  $job = 'demo';

                  $stat->bind_param($name,$salary, $job );

                  // Check connection
                  if ($conn->connect_error) {
                  die("Connection failed: " . $conn->connect_error);
                  }

                  // prepare and bind
                  $stmt = $conn->prepare("INSERT INTO salary (name, salary, job) VALUES (?, ?, ?)");
                  $stmt->bind_param("sss", $firstname, $lastname, $email);

                  // set parameters and execute
                  $firstname = "Johnqqq";
                  $lastname = "123123";
                  $email = "sdadsad";
                  $stmt->execute();

                  echo "New records created successfully";

                  $stmt->close();
                  $conn->close();

                  ?>






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 11 at 10:46









                  Bhavesh Tailor

                  114




                  114






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247783%2fphp-query-wont-insert-to-database%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Full-time equivalent

                      さくらももこ

                      13 indicted, 8 arrested in Calif. drug cartel investigation