-1

I ran into this error:

Fatal error: Uncaught Error: Call to a member function bind_param() on boolean in /storage/ssd5/087/18910087/public_html/admin/connect.php:35 Stack trace: #0 {main} thrown in /storage/ssd5/087/18910087/public_html/admin/connect.php on line 35

I checked my PHP code but I didn't find any error with the names of elements or anything like that

My code:

<?php
    $carname = $_POST['carname'];
    $year = $_POST['year'];
    $manufacturer = $_POST['manufacturer'];
    $price = $_POST['price'];
    $eco = $_POST['eco'];
    $drive = $_POST['drive'];
    $cylinder = $_POST['cylinder'];
    $desc = $_POST['desc'];
    $intName1 = $_POST['intName1'];
    $intDesc1 = $_POST['intDesc1'];
    $intName2 = $_POST['intName2'];
    $intDesc2 = $_POST['intDesc2'];
    $intName3 = $_POST['intName3'];
    $intDesc3 = $_POST['intDesc3'];
    $perName1 = $_POST['perName1'];
    $perDesc1 = $_POST['perDesc1'];
    $perName2 = $_POST['perName2'];
    $perDesc2 = $_POST['perDesc2'];
    $extName1 = $_POST['extName1'];
    $extDesc1 = $_POST['extDesc1'];
    $extName2 = $_POST['extName2'];
    $extDesc2 = $_POST['extDesc2'];
    $extName3 = $_POST['extName3'];
    $extDesc3 = $_POST['extDesc3'];
    $id = $_POST['id'];

    // Database connection
    $conn = new mysqli('localhost','id18910087_admin','@Root2022toor@','id18910087_cars');
    if($conn->connect_error){
        echo "$conn->connect_error";
        die("Connection Failed : ". $conn->connect_error);
    } else {
        $stmt = $conn->prepare("insert into cars(carname, year, manufacturer, price, eco, drive, cylinder, desc, intName1, intDesc1, intName2, intDesc2, intName3, intDesc3, perName1, perDesc1, perName2, perDesc2, extName1, extDesc1, extName2, extDesc2, extName3, extDesc3, id) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
        $stmt->bind_param("sisiisisssssssssssssssssi", $carname, $year, $manufacturer, $price, $eco, $drive, $cylinder, $desc, $intName1, $intDesc1, $intName2, $intDesc2, $intName3, $intDesc3, $perName1, $perDesc1, $perName2, $perDesc2, $extName1, $extDesc1, $extName2, $extDesc2, $extName3, $extDesc3, $id);
        $execval = $stmt->execute();
        echo $execval;
        echo "Registration successfully...";
        $stmt->close();
        $conn->close();
    }
?>
Dharman
  • 26,923
  • 21
  • 73
  • 125
  • I wold start with adding a line to check `mysqli::$error` after you attempt to prepare your statement: https://www.php.net/manual/en/mysqli.error.php. It sounds like that step is failing. – Jerry May 24 '22 at 23:57
  • `desc` is a reserved term, needs to be in backticks. Use mysqli error reporting it would tell you this. This schema also seems like a bad design, I would reconsider the name and the design. – user3783243 May 25 '22 at 00:21
  • 1
    @Jerry there is a much better way that requires to add absolutely nothing. See the pinned answer – Your Common Sense May 25 '22 at 08:18

0 Answers0