phpsqlmysqlidate-formatbindparam

Question about Date format when you use mysqli_stmt_bind_param


I get the value of Date from DatePickerDialog and want to send this through Volley.

Date variable --> Date community_Date

I requested below code

and this is my PHP code.

<?php

    $con=mysqli_connect("localhost", "",
                       "","");
    error_reporting(E_ALL);
    mysqli_query($con, 'SET NAMES utf8');

    $Name = $_POST["Name"];
    $place = $_POST["place"];
    $Number = $_POST["Number"];
    $Date = $_POST["Date"];
    $startTime = $_POST["startTime"];
    $finishTime = $_POST["finishTime"];

    $statement = mysqli_prepare($con, "INSERT INTO community_Register VALUES (?,?,?,?,?,?)");
    mysqli_stmt_bind_param($statement, "ssidii", $Name,$place, $Number, $Date, $startTime, $finishTime);

?>

I'm wondering which Date format I should put in mysqli_stmt_bind_param($statment, "ssidii" <-- this point.

I want to change "d"


Solution

  • You should always use s. So in your case ssssss.

    mysqli_stmt_bind_param($statement, "ssssss", $Name,$place, $Number, $Date, $startTime, $finishTime);
    

    The date should be a string formatted as Y-m-d or Y-m-d H:i:s

    d in bind_param() stands for double and it represents a number not a date.

    If you need to format the date you can use DateTime class

    $Date = (new \DateTime($_POST["Date"]))->format('Y-m-d');