Blaze Blue
Blaze Blue

Reputation: 15

Can't Insert data in MySql Table, but i can retrieve data just fine

I can conect to my database just fine, but whenever I try to insert data I get a "Call to a member function bind_param() on a non-object" error, which I know means that I must have mistyped the name of a slot, or something, but I just can't see it, I'm connecting locally, do I have to set up something in MyPhP to allow data to be added from a php file? Thanks in advance.

<?php

include 'connect.php';

if (isset($_POST['Slot1'])) {
    $Slot1 = $_POST['Slot1'];
}

if (isset($_POST['Slot2'])) {
    $Slot2 = $_POST['Slot2'];
}

if (isset($_POST['Slot3'])) {
    $Slot3 = $_POST['Slot3'];
}

if (isset($_POST['Slot4'])) {
    $Slot4 = $_POST['Slot4'];
}

if (isset($_POST['Slot5'])) {
    $Slot5 = $_POST['Slot5'];
}

if (isset($_POST['Slot6'])) {
    $Slot6 = $_POST['Slot6'];
}

if (isset($_POST['Slot7'])) {
$Slot7 = $_POST['Slot7'];
}

$stmt = $db->prepare("INSERT INTO `tabel` (Slot1, Slot 2, Slot3, Slot4,Slot5,
                                        Slot6, Slot7)
                                        VALUES (?, ?, ?, ?, ?, ?,?");

$stmt->bind_param('sssssss',$Slot1,$Slot2,$Slot3,$Slot4,$Slot5,$Slot6,$Slot7);
$stmt->execute();
$stmt->close();

header("Location: Display.php")
?>

Upvotes: 0

Views: 82

Answers (2)

Muhammad Arif
Muhammad Arif

Reputation: 1022

Try to change your query to

$stmt = $db->prepare("INSERT INTO `tabel` (Slot1, Slot 2, Slot3, Slot4,Slot5,Slot6, Slot7)VALUES (?, ?, ?, ?, ?, ?,?)");

Upvotes: 1

codeGig
codeGig

Reputation: 1064

You have missed one end parenthese Replace

$stmt = $db->prepare("INSERT INTO `tabel` (Slot1, Slot 2, Slot3, Slot4,Slot5,
                                        Slot6, Slot7)
                                        VALUES (?, ?, ?, ?, ?, ?,?");

To

$stmt = $db->prepare("INSERT INTO `tabel` (Slot1, Slot 2, Slot3, Slot4,Slot5,
                                        Slot6, Slot7)
                                        VALUES (?, ?, ?, ?, ?, ?,?)");

Upvotes: 3

Related Questions