如何将用户输入发送到php,执行sql命令并显示来自php的输出 [英] how to send user input to php, excute sql command and display output from php

查看:62
本文介绍了如何将用户输入发送到php,执行sql命令并显示来自php的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序是这样工作的.html页面上有三个按钮,它们链接到导致xml的三个不同的php文件,结果基于oracle中固定的sql命令.当用户单击按钮之一时,例如.

my program works like this. there are three buttons on html page which are linking to three different php files which result in xml, result are based on fixed sql command in oracle. when user click on one of the button eg.

    <p><input class="fetchSeries" type="button" value="CurrValue">  
  <a href="connectyf.php"> </a>  
  <span></span>
  </p>

然后它将触发下面的ajax,并在html页面上绘制图形

it will then trigger the below ajax, and to plot a graph on html page

 $("input.fetchSeries").click(function () {
     var button = $(this);  
     var dataurl = button.siblings('a').attr('href');
     $.ajax({
     url: dataurl,
     type: "GET",
 cache: false,
     success: function (data2) {
      $(data2).find('node').each(function(){
      var currV = $(this).find('snv').text();
      var dateT =   ($(this).find('agev').text())*1000;
      var d2 = [];
      d2.push(dateT, currV);
      dataset.push(d2);
      button.siblings('span').text('Fetched '  + ', first point: ' );
     })
   data.push(dataset);
   $.plot(placeholder, data,options);
   dataset = [];
  }
    }); 
  });

sql命令:

   $sql = "SELECT TO_CHAR(DATETIME, 'YYYY-MM-DD HH24:MI:SS') AS DATETIME, PRESENTSTATE
   FROM T00000000_01080413 WHERE DATETIME BETWEEN '04-OCT-11' AND '15-OCT-11' ";

我现在要做的是放置四个用户输入字段和一个按钮,单击该按钮以控制sql命令,如果我没记错的话,在php页面中应该是这样的

what i need to do now is place four user input field and one button, click the button to control the sql command, something should be like this in php page if im not mistaken

$sql = "SELECT TO_CHAR(DATETIME, 'YYYY-MM-DD HH24:MI:SS') AS '$_POST[datetime]', '$_POST[vall]' FROM T00000000_01080413 WHERE DATETIME BETWEEN '$_POST[startdate]' AND '$_POST[enddate]' ";

现在我有点头疼,一旦单击按钮,如何使用用户输入作为sql命令并绘制图形?

now im a bit headache how do i use the user input as sql command and plot the graph once i click the button?

是否可以使用输入[name = startdate];像那样的东西?现在头疼.请给我启发.提前很多

is it may use the input[name=startdate]; something like that? soooo headache now.please inspire me.... thx so much in advance

  <form method="post" > 
    <div> 
        <input type="text" class="form-text required" value="" size="15" id="edit-name" name="startd" maxlength="60"> 
        <input type="text" class="form-text required" value="" size="15" id="edit-name" name="endd" maxlength="60"> 
        <input type="text" class="form-text required" value="" size="15" id="edit-name" name="pname" maxlength="60"> 
        <input type="text" class="form-text required" value="" size="15" id="edit-name" name="val" maxlength="60"> 
      <input class="fetchSeries" type="button" value="draw graph!"/> 
    </div>
  </form> 














$.ajax({
  type: "POST",
  url: "connectyf1.php",
  data: "startdate="+startdt+"&enddate="+enddt+"&tablename="+tname+"&parameter"+param,
  success: function(grapHtml){

    $("#graph").append(graphHtml); 

 $.ajax({
               url: "connectyf1.php",
               type: "GET",
       cache: false,
               success: function (data2) { 
  $(data2).find('node').each(function(){
  var currV = $(this).find('snv').text();
  var dateT =   ($(this).find('agev').text())*1000;
  var d2 = [];
  d2.push(dateT, currV);
   dataset.push(d2);
  button.siblings('span').text('Fetched '  + ', first point: ' );
  })
   data.push(dataset);
    $.plot(placeholder, data,options);
        dataset = [];
  }
    });

   }
  });

推荐答案

如果您使用的是jquery(1.5或更高版本),则可以使用以下方法进行ajax调用:

If you are using jquery (version 1.5 or higher) you can make an ajax call by using this:

var startd = $('input[name="startd"]').val();

$.ajax({
  type: "POST",
  url: "some.php",
  data: "startd="+startd+"&location=Boston",
  success: function(grapHtml){
    $("#graph").append(graphHtml);
  }
});

这会向some.php发出发布请求.该文件将接收$ _POST ['startd']和$ _POST ['location']值.

This makes a post request to some.php. This file will receive $_POST['startd'] and $_POST['location'] values.

这篇关于如何将用户输入发送到php,执行sql命令并显示来自php的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆