Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

arrays - Have problems to send JSON via POST method in PHP

In Laravel 8 framework I have my array in $getDates which get dates depend of week days.

**

$start = '2020-12-12';
$end = '2021-02-15';
$getDates=[];
$monday=1;
$tuesday=0;
$wednesday=1;
$thursday=0;
$friday=0;
$saturday=0;
$sunday=0;
$start = new DateTime($start);
$end = new DateTime($end);
while($start <= $end ){
    $time_stamp = strtotime($start->format('Y-m-d'));
    $newdate = date ( 'd M Y D' , $time_stamp ); ;
    $week = date('l', $time_stamp);
    if ($sunday==1) {
        if ($week == 'Sunday')
            $getDates[]=[$newdate,'0',''];
    }
    if ($monday==1) {
        if ($week == 'Monday')
            $getDates[]=[$newdate,'0',''];
    }
    if ($tuesday==1) {
        if ($week == 'Tuesday')
            $getDates[]=[$newdate,'0',''];
    }
    if ($wednesday==1) {
        if ($week == 'Wednesday')
            $getDates[]=[$newdate,'0',''];
    }
    if ($thursday==1) {
        if ($week == 'Thursday')
            $getDates[]=[$newdate,'0',''];
    }
    if ($friday==1) {
        if ($week == 'Friday')
            $getDates[]=[$newdate,'0',''];
    }
    if ($saturday==1) {
        if ($week == 'Saturday')
            $getDates[]=[$newdate,'0',''];
    }
    $start->modify('+1 day');
}
$getDates_json=json_encode($getDates); //make json from array
<form method="post" action="{{route('add_new_course')}}">
        @csrf
<input type="hidden" name="schedule" value=<?php echo $_POST['schedule'] ?> />
    <p align="center">
        <input type="submit" class="btn btn-success" value="CREATE COURSE">
        <br>
        <a href="/courses" class="btn btn-info">Return</a>
    </p>
</form>

**

// And I try get JSON format to $getDates_json, and its looks

"[["14 Dec 2020 Mon","0",""],["16 Dec 2020 Wed","0",""],["21 Dec 2020 Mon","0",""],["23 Dec 2020 Wed","0",""],["28 Dec 2020 Mon","0",""],["30 Dec 2020 Wed","0",""],["04 Jan 2021 Mon","0",""],["06 Jan 2021 Wed","0",""],["11 Jan 2021 Mon","0",""],["13 Jan 2021 Wed","0",""],["18 Jan 2021 Mon","0",""],["20 Jan 2021 Wed","0",""],["25 Jan 2021 Mon","0",""],["27 Jan 2021 Wed","0",""],["01 Feb 2021 Mon","0",""],["03 Feb 2021 Wed","0",""],["08 Feb 2021 Mon","0",""],["10 Feb 2021 Wed","0",""],["15 Feb 2021 Mon","0",""]]"

and when I send it by POST method I get value looks

[["14

If some body know how I can send this JSON via POST for INSERT to MySQL DB? In the end, I need sometimes update information inside JSON and put it back to DB.

question from:https://stackoverflow.com/questions/65930638/have-problems-to-send-json-via-post-method-in-php

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...