CamilleTanyawen / 2020-GPW-L5K2-B

1 stars 0 forks source link

problem #11

Open yingwuqian opened 4 years ago

yingwuqian commented 4 years ago

@jslemmer Hi! Jons. Can you check this code for me? I made a dynamic bus route table which can drag and drop to modify the date and time of the bus times, but inserting data from the web page always shows input failed, it can only insert from the database. I think there's a little problem with the query. @https://l5k2b.instantcloud.cn/login.php username: Alisa password: 0000

`<?php

include_once('db.php');

$action = $_GET['action']; if ($action == 'add') { $title = $_POST['title']; $allday = $_POST['allday'] == 'true' ? 1 : 0; $startdate = trim($_POST['startdate']); $s_time = $_POST['s_hour'] . ':' . $_POST['s_minute']; $starttime = strtotime($startdate . ' ' . $s_time);

$sql = "insert into `calendar` (`title`,`starttime`,`allday`) values ('$title','$starttime','$allday')";
$query = mysqli_query($connection, $sql);
if (mysqli_insert_id($connection) > 0) {
    echo '1';
} else {
    echo 'Input failed!';
}

} else if ($action == "drag") { $id = $_POST['id']; $daydiff = (int) $_POST['daydiff'] 24 60 * 60; $minudiff = (int) $_POST['minudiff'] / 1000; $allday = $_POST['allday'] == 'true' ? 1 : 0; $difftime = $daydiff + $minudiff;

$sql = "update `calendar` set starttime=starttime+'$difftime',allday='$allday' where id='$id'";
$result = mysqli_query($connection, $sql);
if (mysqli_affected_rows($connection) == 1) {
    echo '1';
} else {
    echo 'error!';
}

} ?>` image

9sa6c commented 4 years ago

Echo your $query. So put that on the screen. Maybe the easiest place to do that is to change

echo 'Input failed!';

to

echo '$query';

After that check the query you are outputting against the database (use PMA to test) and see if there is a query issue

9sa6c commented 4 years ago

Sorry it should be like this

echo '$sql';

yingwuqian commented 4 years ago

after input the echo '$sql'; it show the image

9sa6c commented 4 years ago

Your code is not loading anymore on the server.

But the idea is the following, make the $sql appear some where, so you can try to check it for any issues.