Похожие чаты

Please someone help is not sending it to my database

I try it morethan 20 times 😭😭😭😭
<?php

$dbServer = "localhost";
$dbUsername = "airfashi_sani20";
$dbPassword = "muhammad@20";
$dbName = "airfashi_fashion";

// Establish a database connection
$conn = new mysqli($dbServer, $dbUsername, $dbPassword, $dbName);

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

// Check if it's a POST request
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Check if POST data is set
    if (isset($_POST['reference'], $_POST['total'], $_POST['fullName'], $_POST['address'], $_POST['phoneNumber'], $_POST['deliveryType'], $_POST['productId'], $_POST['email'])) {
        // Retrieve data from the POST request
        $reference = $_POST['reference'];
        $total = $_POST['total'];
        $fullName = $_POST['fullName'];
        $address = $_POST['address'];
        $phoneNumber = $_POST['phoneNumber'];
        $deliveryType = $_POST['deliveryType'];
        $productId = $_POST['productId'];
        $email = $_POST['email'];

        // Use Prepared Statements to prevent SQL injection
        $sql = "INSERT INTO payments (reference, total, full_name, address, phone_number, delivery_type, product_id, email) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
        $stmt = $conn->prepare($sql);
        $stmt->bind_param("ssssssss", $reference, $total, $fullName, $address, $phoneNumber, $deliveryType, $productId, $email);

        // Execute the query
        if ($stmt->execute()) {
            $response = array('status' => 'success', 'message' => 'Payment details inserted successfully');
        } else {
            $response = array('status' => 'error', 'message' => 'Error inserting payment details: ' . $stmt->error);
        }

        // Close the database connection
        $stmt->close();
        $conn->close();
    } else {
        $response = array('status' => 'error', 'message' => 'Incomplete POST data');
    }

    // Send the response back to the JavaScript code
    echo json_encode($response);
}

?>

4 ответов

28 просмотров

It will be better if you send the error message you getting

Send what is error ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);

Put this code on ChatGpt it'll tell you the error 😏

Number of bound parameters does not much what you want to insert there

Похожие вопросы

Обсуждают сегодня

А кто-то пробовал, уезжая из Эстонии получить э-рез и продолжить вести предпринимательскую деятельность внутри Эстонии, используя свой OÜ?
Lalalashechki Lalala
62
@MrMiscipitlick А можешь макрос написать, который будет вычислять смещение относительно переданных меток? Просто .label1-.label2, и вернуть значение.
КТ315
35
Чем оно проблема?
Nikita Uzumaki
21
@samkazemian - couple questions: Update on frxBTC? - This would do well with the current influx of institutional investment entering the space Update on future veFXS streams...
Costi
16
я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
100
А еще в перле можно уже @arr1 + @arr2?
Sergei Zhmylove
53
Подобного рода ;Следующие три строки это директивы ассемблера, ;которые можно не задавать, т.к.работаем в Visual Studio. ;Символ ";" - это начало однострочного комментария ...
Егор Анелькин
3
Does anyone here have a connection Mullvad? it would be nice to know what it would take to have them accept BCH 0-conf.
tl121x
16
Can an XMR transaction be tracked from its sender to its receiver by performing blockchain analysis, no matter how many addresses are used?
Trkz342
16
I arrived here after a Chico Crypto show highlighted the project & the Team - the fact that the Team had a long history of successfully working with household names gave me e...
Banter is Bullish
5
Карта сайта