如何将值传递给php以获取表作为输出?

时间:2014-12-30 06:28:57

标签: javascript php html

<script type="text/javascript">
    function OnSliderChanged (slider) {
        var sliderValue = document.getElementById (slider.id + "Value");
        sliderValue.innerHTML = slider.value;
    }

    function Init () {
        var slider = document.getElementById ("slider1");
        OnSliderChanged (slider);
        var slider = document.getElementById ("slider2");
        OnSliderChanged (slider);
    }
</script>
0<input type="range" id="slider1" min="0" max="100" step="1" style=width:50% onchange="OnSliderChanged (this)" />100
<span id="slider1Value" class="sliderValue"></span>
<br /><br /><br />
0<input type="range" id="slider2" min="0" max="100" step="1" style=width:50% onchange="OnSliderChanged (this)" />100
<span id="slider2Value" class="sliderValue"></span>
<br>
<input type="submit" onmouseover="this.style.cursor=\'pointer\';" OnMouseOut="this.style.cursor=\'default\';">


<?php
if (isset($_GET['value=20'&&'value1=40']))
{
$username = 'root';
$password = '';
$hostname = 'localhost';
$dataname = mysql_connect($hostname,$username,$password) or die("Connection failed: ");
$selected = mysql_select_db('testdb',$dataname) or die("Could not select table1");
$result = mysql_query("SELECT * FROM `table1`");
$last = '';
echo "<table>
    <tr>
        <th>id</th>
        <th>name</th>
    </tr>";
 while($row = mysql_fetch_array($result))
 {
 echo"<tr>
         <td>".$row['0']."</th>
         <td>".$row['1']."</td>
  </tr>"; 
  }
 mysql_close($dataname);
 }
else
{
echo " No Values Found";
}
 ?>

我正在尝试将输入值输入到应该显示该表的php中。但是我没有得到表格,因为我在初始页面本身得到“No values Found”。我是这个php n javascript的新手..例如,当输入值20 n 40作为输入时,我需要获取表...有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

您必须在html表单中使用name属性才能在服务器端访问它们。

0<input type="range" name="value" id="slider1" min="0" max="100" step="1" style=width:50% onchange="OnSliderChanged (this)" />100
<span id="slider1Value" class="sliderValue"></span>
<br /><br /><br />
0<input type="range" name="value1" id="slider2" min="0" max="100" step="1" style=width:50% onchange="OnSliderChanged (this)" />100
<span id="slider2Value" class="sliderValue"></span>
<br>
<input type="submit" onmouseover="this.style.cursor=\'pointer\';" OnMouseOut="this.style.cursor=\'default\';">

同时将表单方法改为发布 method="post"