嗨我通过$ .ajax方法发送一个表单值,它发送正确的日期,但我的PHP脚本存储它作为0000-00-00。即使我回应我的SQL查询并在我的管理员测试,但存储个人技术
这是我的Jquery
// saving purpose
$(document).on('click','#btn-add',function(){
$('#save-from').modal({show:true});
$(document).on('click','#add-save',function(){
var amc_id = $('#amc_id').val();
var amc_type = $('#amc_type').val();
var amc_start_date = $('#amc_start_date').val();
var amc_end_date = $('#amc_end_date').val();
var renual_date = $('#renual_date').val();
var renual_ammount = $('#renual_ammount').val();
var client_id = $('#client_id').val();
var machine_id = $('#machine_id').val();
if(amc_type === ""){
$('#amc_type').focus();
$('#amc_type').val('Enter enter amc tyoe');
return;
}
$.ajax({
url:"include/insert-amc-class.php",
type: "POST",
data:{'amc_id':amc_id, 'amc_type':amc_type, 'amc_start_date':amc_start_date, 'amc_end_date':amc_end_date, 'renual_date':renual_date,'renual_ammount':renual_ammount,'client_id':client_id,'machine_id':machine_id},
dataType:"text",
success:function(html){
$('#save-from').modal('hide');
$('#modal-success').modal({show:true});
}
});
});
});// end of save
这是我的PHP脚本
<?php
include_once "db_config.php";
class AMC{
public $db;
public function __construct(){
$this->db = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
if(mysqli_connect_errno()) {
echo "Error: Could not connect to database.";
exit;
}
}
// to save amc details to database, to be called into amc-page.php
public function insertAmc($amc_id,$amc_type,$amc_start_date,$amc_end_date,$renual_date,$renual_ammount,$client_id,$machine_id){
$sql = "INSERT INTO `amc`(`amc_id`, `amc_type`, `amc_start_date`, `amc_end_date`, `renual_date`, `renual_ammount`, `client_id`, `machine_id`) VALUES ('$amc_id','$amc_type','$amc_start_date','$amc_end_date','$renual_date','$renual_ammount','$client_id','$machine_id')";
$result = mysqli_query($this->db,$sql);
echo $sql;
return $result;
}
}
$amc = new AMC();
$amc_id = $_POST['amc_id'];
$amc_type = $_POST['amc_type'];
$amc_start_date= $_POST['amc_start_date'];
$amc_end_date = $_POST['amc_end_date'];
$renual_date = $_POST['renual_date'];
$renual_ammount = $_POST['renual_ammount'];
$client_id = $_POST['client_id'];
$machine_id = $_POST['machine_id'];
$amc->insertAmc($amc_id,$amc_type,$amc_start_date,$amc_end_date,$renual_date,$renual_ammount,$client_id,$machine_id);
?>
这是我回应它时的SQL查询
INSERT INTO `amc`(`amc_id`, `amc_type`, `amc_start_date`, `amc_end_date`, `renual_date`, `renual_ammount`, `client_id`, `machine_id`) VALUES ('7','4c','31-08-2016','27-01-2017','','70000','1','1')
答案 0 :(得分:0)
您应该告诉查询您正在插入日期及其格式如下所示:
/*
* The application has been developed and supported by mauricio_gonzalez
* Automation Development Area of Sanmina P02 has the rights of the application
* Don't modify the code without permission, please contact us by mauricio.gonzalez@sanmina.com | yair.avalos@sanmina.com
*/
package protocols;
import java.io.*;
import java.util.*;
import javax.swing.JTextArea;
/**
*
* @author mauricio_gonzalez
*/
public class TCP_IP {
public void userAdd (String data, JTextArea textarea)
{
String message, add = ": :Connect", done = "Server: :Done", name = data;
textarea.append("Before " + name + " added. \n");
my.protinterface.PROTInterface.users.add(name);
textarea.append("After " + name + " added. \n");
String[] tempList = new String[(my.protinterface.PROTInterface.users.size())];
my.protinterface.PROTInterface.users.toArray(tempList);
for (String token:tempList)
{
message = (token + add);
tellEveryone(message, textarea);
}
tellEveryone(done, textarea);
}
public void userRemove (String data, JTextArea textarea)
{
String message, add = ": :Connect", done = "Server: :Done", name = data;
my.protinterface.PROTInterface.users.remove(name);
String[] tempList = new String[(my.protinterface.PROTInterface.users.size())];
my.protinterface.PROTInterface.users.toArray(tempList);
for (String token:tempList)
{
message = (token + add);
tellEveryone(message, textarea);
}
tellEveryone(done, textarea);
}
public void tellEveryone(String message, JTextArea textarea)
{
Iterator it = my.protinterface.PROTInterface.clientOutputStreams.iterator();
while (it.hasNext())
{
try
{
PrintWriter writer = (PrintWriter) it.next();
writer.println(message);
textarea.append("Sending: " + message + "\n");
writer.flush();
textarea.setCaretPosition(textarea.getDocument().getLength());
}
catch (Exception ex)
{
textarea.append("Error telling everyone. \n");
}
}
}
}