duanchen7036
2014-12-30 06:28
浏览 51
已采纳

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

<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";
}
 ?>

I am trying to get the input values into the php which should show the table.But am not getting the table as result am getting "No values Found" in the initial page itself. Am new to this php n javascript.. For eg i need to get the table when values 20 n 40 entered as input...Can someone please help me..?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doutu3352 2014-12-30 06:35
    已采纳

    You have to use name attribute in html form in order to access them in server side..

    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\';">
    

    Also make the form method to post with method="post"

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题