我正在创建一个PHP互动的音乐网站,其中a 用户将能够查看艺术家的个人资料,并根据他们评分 属性:使用表单的文字游戏,流程,隐喻和魅力 范围滑块。
我希望它能让观众观看 调整范围滑块时,滑块旁边会显示相应的值。然后,当观众提交表单时,我希望将值输入数据库' lr'进入表格属性,其中包含列" Wordplay","流程","隐喻"和"魅力"采用INT格式。
这是我到目前为止所拥有的。有人可以帮帮我吗?
<小时/> profilepage.html.php
<html>
<body>
<form action="?submitattr" method="POST" style="display:block">
<label for=Wordplay>Wordplay: </label>
<input type=range min=50 max=100 value=75 step=1 id=fader>
<output for=fader class=value name=outputwordplay>75</output><br>
<label for=Flow>Flow: </label>
<input type=range min=50 max=100 value=75 step=1 id=fader1>
<output for=fader1 class=value name=outputflow>75</output><br>
<label for=Metaphors>Metaphors: </label>
<input type=range min=50 max=100 value=75 step=1 id=fader2>
<output for=fader2 class=value name=outputmetaphors>75</output><br>
<label for=Charisma>Charisma: </label>
<input type=range min=50 max=100 value=75 step=1 id=fader3>
<output for=fader3 class=value name=outputcharisma>75</output><br>
<input type=submit name=submit value=Submit>
</form>
</body>
</html>
<小时/> ` 的index.php
<?php
$link = mysqli_connect('localhost','root','xxxxx','xxxxx');
if(isset($_POST['submitattr'])){
$wordplay = $_GET['outputwordplay'];
$flow = $_GET['outputflow'];
$metaphors = $_GET['outputmetaphors'];
$charisma = $_GET['outputcharisma'];
$sql = "INSERT INTO attributes (Wordplay,Flow, Metaphors,Charisma) VALUES('$wordplay','$flow','$metaphors','$charisma')";
$query = mysqli_query($link, $sql);
if(!$query){
echo "Couldn't enter data";
}
else{
echo "Data entered";
}
}
include 'profileuser.html.php';
?>
答案 0 :(得分:0)
您的HTML和JavaScript部分应如下所示:
$(document).ready(function () {
$('output[for=wordplay]').html($('#wordplay').val());
$('#wordplay').bind('change', function () {
$('output[for=wordplay]').html($('#wordplay').val());
});
$('output[for=flow]').html($('#flow').val());
$('#flow').bind('change', function () {
$('output[for=flow]').html($('#flow').val());
});
$('output[for=metaphors]').html($('#metaphors').val());
$('#metaphors').bind('change', function () {
$('output[for=metaphors]').html($('#metaphors').val());
});
$('output[for=charisma]').html($('#charisma').val());
$('#charisma').bind('change', function () {
$('output[for=charisma]').html($('#charisma').val());
});
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form method="post" action="?submitattr">
<label for="wordplay">Wordplay:
<input type="range" name="wordplay" step="1" id="wordplay" min="0" max="100" />
<output for="wordplay"></output>
</label>
<br />
<label for="flow">Flow:
<input type="range" name="flow" step="1" id="flow" min="0" max="100" />
<output for="flow"></output>
</label>
<br />
<label for="metaphors">Metaphors:
<input type="range" name="metaphors" step="1" id="metaphors" min="0" max="100" />
<output for="metaphors"></output>
</label>
<br />
<label for="charisma">Charisma:
<input type="range" name="charisma" step="1" id="charisma" min="0" max="100" />
<output for="charisma"></output>
</label>
<br />
<input type="submit" name="submit" value="Submit" />
</form>
&#13;
在PHP部分中,您只需更改几行:
$wordplay = $_POST['wordplay'];
$flow = $_POST['flow'];
$metaphors = $_POST['metaphors'];
$charisma = $_POST['charisma'];
首先,您必须使用HTML中声明的post方法。此外,您必须获取输出元素的输入NOT的值。