javascript - ajax post to php not actually writing to the mysql table -


$(document).ready(function() {     $('#save').click(function() {          var rows = [];          (i = 1 ; < document.getelementbyid("schedule").rows.length ; i++) {             var name;             var tuesday;             var wednesday;             var thursday;             var friday;             var saturday;             var sunday;              name = document.getelementbyid("schedule").rows[i].cells[0].firstchild.value;             tuesday = document.getelementbyid("schedule").rows[i].cells[1].firstchild.value;             wednesday = document.getelementbyid("schedule").rows[i].cells[2].firstchild.value;             thursday = document.getelementbyid("schedule").rows[i].cells[3].firstchild.value;             friday = document.getelementbyid("schedule").rows[i].cells[4].firstchild.value;             saturday = document.getelementbyid("schedule").rows[i].cells[5].firstchild.value;             sunday = document.getelementbyid("schedule").rows[i].cells[6].firstchild.value;             monday = document.getelementbyid("schedule").rows[i].cells[7].firstchild.value;              rows[i-1] = "name=" + name + "&tuesday=" + tuesday + "&wednesday=" + wednesday + "&thursday=" + thursday + "&friday=" + friday + "&saturday=" + saturday + "&sunday=" + sunday + "&monday=" + monday;         }          (i = 0 ; < rows.length ; i++) {             $.ajax({             type: "post",             url: "save-schedule.php",             data: rows[i],             success: function () {                 alert("post successful");             }             });         }     }); }); 

the javascript array working correctly , showing correct format , ajax success function executing. shows alert "post successful" after checking mysql table empty.

<?php $servername = "localhost"; $username = ""; $password = "";  $conn = new mysqli($servername, $username, $password);  if ($conn->connect_error) {     die("connection failed: " . $conn->connect_error); }  $conn->select_db("little_caesar");  $name=$_post["name"]; $tuesday=$_post["tuesday"]; $wednesday=$_post["wednesday"]; $thursday=$_post["thursday"]; $friday=$_post["friday"]; $saturday=$_post["saturday"]; $sunday=$_post["sunday"]; $monday=$_post["monday"];  $conn->query("insert schedule (name,tuesday,wednesday,thursday,friday,saturday,sunday,monday) values('$name','$tuesday','$wednesday','$thursday','$friday','$saturday','$sunday','$monday')");  $conn->close(); ?> 

this save-schedule.php great! in advance!

remove '&' symbol ajax data change instead of , symbol like

rows[i-1] = "{name=" + name + ",tuesday=" + tuesday + ",wednesday=" + wednesday + ",thursday=" + thursday + ",friday=" + friday + ",saturday=" + saturday + ",sunday=" + sunday + ",monday=" + monday+"}"; 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -