weixin_33701294 2016-02-15 14:58 采纳率: 0%
浏览 27

Mysql通过Ajax插入查询

I've searched the internet and found something about using ajax for setting information in my database. I found this page, but it shows how to GET info from your database.

Is it also possible to SET information in the database?

I use this for a schedule.

in my DB I have a table that contains the following columns:

  • Startdate
  • Enddate
  • Productdescription
  • Expected production
  • actual Production
  • Difference

When they create the schedule they only know the first four. The other two need to be filled in automatically. I do this when the production is finished:

I've made a small start about checking if the production is done:

setInterval(function()
{
    var currentTime = new Date();
    var endProductionTimeMachine1 = <?php echo json_encode($TempomaticRow1[0]['Einddatum']) ?>; // get the enddate from the database via php
    var ActualProductionToday = 2100; //just an example value

    //Convert mysql date to javascript date
    var t = endProductionTimeMachine1.split(/[- :]/);
    var endProdTimeMachine1 = new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]);

    if(currentTime == endProdTimeMachine1)
    {
         //set information in the DB        
    }
},1000);

So I would like to know if I can call a php page that inserts information into my database with a parameter from this page.

  • 写回答

2条回答 默认 最新

  • weixin_33690963 2016-02-15 15:04
    关注

    Use that page and modify the AJAX call so that it triggers a PHP script which will then update your database. Send all information necessary to the server. In order to change the database, make use of "prepared statements" either via MySQLi or PDO.
    Never send a SQL query from a client to a server! Always only send the values and have the server build the query!

    For a complete example, you can also take a look at this: http://www.plus2net.com/php_tutorial/display-record-edit.php

    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试