1

I'm trying to integrate the HTML page with the database I have created, and I have looked at many tutorials as well as looked at previous questions related to this issue, but I couldn't come up with a solution. The HTML page connection to the localhost is fine, but my issue is when I insert the values into the table I get this error: "Fatal error: Uncaught Error: Call to a member function execute() on bool in C:\xampp\htdocs\HTML\details_entry.php:29 Stack trace: #0 {main} thrown in C:\xampp\htdocs\HTML\details_entry.php on line 29"

HTML

  <?php
 include_one 'includes/details_entry.php';
  ?>

  <!DOCTYPE html>
  <html>

  <head>
        <meta charset="utf-8">

  <style>
        h1 {text-align: center;}

    </style>

        <title>Multiple sliders</title>

        <link rel="stylesheet" href="./style.css">
  </head>
  <body>
        <body text = "black">
        <!-- Heading -->
        <h1>  Multiple sliders </h1>

        <form action = "details_entry.php" method="POST">


  <div class="slidecontainer">

    <input type="range" name="demo" min="0" max="180" value="90" class="slider" id="myRange">
    <p>Value: <span id="demo"></span></p> <label> Slider 1</label>
  </div>

  <div class="slidecontainer">
    <input type="range" name="demo2" min="0" max="180" value="90" class="slider" id="myRange2">
     <p>Value: <span id="demo2"></span></p> <label> Slider 2</label>
  </div>

  <div class="slidecontainer">
    <input type="range" name="demo3" min="0" max="180" value="90" class="slider" id="myRange3">
  <p>Value: <span id="demo3"></span></p>  <label> Slider 3</label>
  </div>

  <div class="slidecontainer">
    <input type="range" name="demo4" min="0" max="180" value="90" class="slider" id="myRange4">
    <p>Value: <span id="demo4"></span></p> <label> Slider 4</label>
  </div>

  <div class="slidecontainer">
    <input type="range" name="demo5" min="0" max="180" value="90" class="slider" id="myRange5">
    <p>Value: <span id="demo5"></span></p> <label>Slider 5</label>
  </div>

  <div class="slidecontainer">
    <input type="range" name="demo6" min="0" max="180" value="90" class="slider"                    id="myRange6">
    <p>Value: <span id="demo6"></span></p> <label> Slider 6</label>
  </div>

  <div class="wrapper">
      <button class="button" name="save" >Save</button>
  </div>

  <div class="button10" >
   <button class="button1" name="on" > On/Off </button>
  </div>





  <script>
  var slider1 = document.getElementById("myRange");
  var demo = document.getElementById("demo");
  demo.innerHTML = slider1.value;

  slider1.oninput = function() {
    demo.innerHTML = this.value;
  }
  </script>

  <script>
  var slider2 = document.getElementById("myRange2");
  var output = document.getElementById("demo2");
  output.innerHTML = slider2.value;

  slider2.oninput = function() {
    output.innerHTML = this.value;
  }
  </script>

  <script>
  var slider3 = document.getElementById("myRange3");
  var output3 = document.getElementById("demo3");
  output3.innerHTML = slider3.value;

  slider3.oninput = function() {
    output3.innerHTML = this.value;
  }
  </script>


  <script>
  var slider4 = document.getElementById("myRange4");
  var demo4 = document.getElementById("demo4");
  demo4.innerHTML = slider4.value;

  slider4.oninput = function() {
    demo4.innerHTML = this.value;
  }
  </script>
  
  <script>
  var slider5 = document.getElementById("myRange5");
  var output5 = document.getElementById("demo5");
  output5.innerHTML = slider5.value;

  slider5.oninput = function() {
    output5.innerHTML = this.value;
  }
  </script>

  <script>
  var slider6 = document.getElementById("myRange6");
  var output6 = document.getElementById("demo6");
  output6.innerHTML = slider6.value;

  slider6.oninput = function() {
    output6.innerHTML = this.value;
  }
  </script>

   </form>


  </body>
  </html>

PHP

    <?php
    $host = "localhost";
    $dbUsername = "root";
    $dbPassword ="";
    $dbName= "robot_arm_values";
    $slider = $_POST ['demo'];
    $slider2 = $_POST ['demo2'];
    $slider3 = $_POST ['demo3'];
    $slider4 = $_POST ['demo4'];
    $slider5 = $_POST ['demo5'];
    $slider6 = $_POST ['demo6'];

    $conn = new mysqli($host,$dbUsername,$dbPassword,$dbName);

    if(mysqli_connect_error()){
        die ('Connect Error('.mysqli_connect_errno().')'.mysqli_connect_error());
    } else{

        if(isset($_POST['save'])){

            $test = "INSERT INTO testing (value1, value2, value3, value4, value5, value6) values(?,?,?,?,?,?)";
         //Prepare statement

          $stmt = $conn->prepare($test);
      if ($stmt != false)
             $stmt->bind_param("iiiiii", $slider,$slider2,$slider3,$slider4,$slider5,$slider6);
      else
          print("Returns false");
          $stmt->execute();
          echo "Values have been modified successfully!";

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

            } else if(isset($_POST['on'])){


        }

    }

    ?>
Dharman
  • 30,962
  • 25
  • 85
  • 135
Bandar
  • 23
  • 3
  • 1
    Does this answer your question? [Call to a member function execute() on boolean in](https://stackoverflow.com/questions/35132451/call-to-a-member-function-execute-on-boolean-in) – Tangentially Perpendicular Jun 27 '21 at 04:40
  • What's the point of putting `$stmt->execute();` AFTER the `if` statement that checks `if ($stmt != false)`? – Alon Eitan Jun 27 '21 at 04:54
  • @AlonEitan I'm still a beginner I have no idea what most of the statements do, so if I remove it will I get rid of the error? – Bandar Jun 27 '21 at 05:13
  • 1
    Yes and No - If you handle the query logic inside the `if ($stmt != false) { }` then the error will go away, but you won't get anything else because it won't solve the basic fact the the INSERT query itself failed (Read [here](https://www.php.net/manual/en/mysqli.error.php) - This will help you to debug your query) – Alon Eitan Jun 27 '21 at 05:16
  • @AlonEitan I have just checked and got this error "Warning: Undefined array key "demo" in C:\xampp\htdocs\HTML\details_entry.php on line 6", can you let me know why does this error occur? I get this error for all the variables. – Bandar Jun 28 '21 at 03:24

0 Answers0