I have a website due a project within a few hours and I would like to fix this annoying error I have.
I have a form that sends data to build_transaction.php yet I get the error:
Fatal error: Call to a member function bind_param() on boolean in C:\xampp\htdocs\GigaWatt\build_your_rig\build_transaction.php on line 29.
The code for my HTML page is:
<form action="build_transaction.php" method="post">
<label for="cpu">Processor: </label>
<input type="text" id = "cpu" name = "cpu" required><br>
<label for="gpu">Graphics Card: </label>
<input type="text" id = "gpu" name = "gpu" required><br>
<label for="psu">Power Supply (Watts): </label>
<input type="number" id = "psu" name = "psu" value = "0" min = "300" max="2000" required><br>
<label for="motherboard">Motherboard: </label>
<input type="text" id = "motherboard" name = "motherboard" required><br>
<label for="mouse">Mouse: </label>
<input type="text" id = "mouse" name = "mouse" required><br>
<label for="keyboard">Keyboard: </label>
<input type="text" id = "keyboard" name = "keyboard" required><br>
<label for="monitor">Monitor: </label>
<input type="text" id = "monitor" name = "monitor" required><br>
<label for="price">Price: </label>
<input type="number" id = "price" name = "price" required><br>
<input id="submit" type="submit" value="Add Record">
</form>
and the code for my PHP is:
<?php
/* Include "configuration.php" file */
require_once '../database_and_table_setup/configuration.php';
$cpu = filter_input(INPUT_POST, "cpu");
$gpu = filter_input(INPUT_POST, "gpu");
$psu = filter_input(INPUT_POST, "psu");
$motherboard = filter_input(INPUT_POST, "motherboard");
$mouse = filter_input(INPUT_POST, "mouse");
$keyboard = filter_input(INPUT_POST, "keyboard");
$monitor = filter_input(INPUT_POST, "monitor");
$price = filter_input(INPUT_POST, "price");
/* Connect to the database */
$dbConnection = mysqli_connect($dbHost, $dbUsername, $dbPassword, $dbName);
if (mysqli_connect_errno())
{
die("Failed to connect to the database ".$dbName);
}
/* Perform query */
$query = "INSERT INTO gigawatt (cpu, gpu, psu, motherboard, mouse, keyboard, monitor , price) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
$statement = $dbConnection->prepare($query);
$statement->bind_param('ssissssi', $cpu, $gpu, $psu, $motherboard, $mouse, $keyboard, $monitor, $price); /* Valid binding types are: s = string, i = integer, d = double, b = blob */
$statement->execute();
/* Manipulate the query result */
/* We do not manipulate the query result. Instead, we can provide feedback that the record has been added */
if (mysqli_affected_rows($dbConnection) > 0)
{
echo "<p>Record successfully added to database.</p>";
}
else
{
echo "<p>Record not added to database.</p>";
}
/* Close the database connection */
mysqli_close($dbConnection);
/* Provide a link for the user to proceed to a new webpage or automatically redirect to a new webpage
echo "<a href=" . $siteName . "/display_all_records_students.php>Click here to add another record</>";*/
//$newURL = "display_all_records.php";
//header('Location: ' . $newURL);
echo "Successfully Added to DB.";
?>
EDIT: Everything is working now, I was calling the DB name in my query "Gigawatt", the actual table name was "specs"... I feel so silly, excuse me.