- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在链接上尝试了完全相同的代码:- http://www.freezecoders.com/2013/05/store-value-from-onoff-button-in-mysql-database-using-php-ajax.html
索引.php:
<?php
$query=mysql_connect("localhost","root","");
mysql_select_db("freeze",$query);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
<title>iPhone Style Radio and Checkbox Switches, found on DevGrow.com</title>
<script type="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
$('#myonoffswitch').click(function(){
var myonoffswitch=$('#myonoffswitch').val();
if ($("#myonoffswitch:checked").length == 0)
{
var a=myonoffswitch;
}
else
{
var a="off";
}
$.ajax({
type: "POST",
url: "ajax.php",
data: "value="+a ,
success: function(html){
$("#display").html(html).show();
}
});
});
});
</script>
<script type="text/javascript">
$(document).ready( function(){
$(".cb-enable").click(function(){
var parent = $(this).parents('.switch');
$('.cb-disable',parent).removeClass('selected');
$(this).addClass('selected');
$('.checkbox',parent).attr('checked', true);
});
$(".cb-disable").click(function(){
var parent = $(this).parents('.switch');
$('.cb-enable',parent).removeClass('selected');
$(this).addClass('selected');
$('.checkbox',parent).attr('checked', false);
});
});
</script>
<style type="text/css">
.onoffswitch {
position: relative; width: 90px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 20px;
}
.onoffswitch-inner {
width: 200%; margin-left: -100%;
-moz-transition: margin 0.3s ease-in 0s; -webkit-transition: margin 0.3s ease-in 0s;
-o-transition: margin 0.3s ease-in 0s; transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "OFF";
padding-left: 10px;
background-color: #2FCCFF; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "ON";
padding-right: 10px;
background-color: #EEEEEE; color: #999999;
text-align: right;
}
.onoffswitch-switch {
width: 18px; margin: 6px;
background: #FFFFFF;
border: 2px solid #999999; border-radius: 20px;
position: absolute; top: 0; bottom: 0; right: 56px;
-moz-transition: all 0.3s ease-in 0s; -webkit-transition: all 0.3s ease-in 0s;
-o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}
</style>
</head>
<body>
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch"
<?php
$query3=mysql_query("select * from choice where id=1");
$query4=mysql_fetch_array($query3);
if($query4['choice']=="off")
{
echo "checked";
}
?>>
<label class="onoffswitch-label" for="myonoffswitch">
<div class="onoffswitch-inner"></div>
<div class="onoffswitch-switch"></div>
</label>
</div>
<div id="display"></div>
</body>
</html>
还有这个 ajax.php:-
<?php
$query=mysql_connect("localhost","root","");
mysql_select_db("freeze",$query);
if(isset($_POST['value']))
{
$value=$_POST['value'];
mysql_query("update choice set choice='$value' where id='1'");
echo "<h2>You have Chosen the button status as:" .$value."</h2>";
}
?>
但事实是它在我的 wamp 服务器上不起作用。此代码引发很多错误,例如: Deprecated: mysql_connect(): The mysql extension is deprecated and will be returned in the future: use mysqli or PDO instead in C:\wamp\www\btn\index.php on line 2和:- 第 109 行出现 mysqli_fetch_array() 错误。给定的代码有什么问题?有谁可以帮我解决这个问题吗?
最佳答案
答案已经在您在问题中发布的错误中。您正在使用旧的 mysql 方法,这些方法在新 php 中已弃用,因此您必须使用 mysqli(改进的 mysql)方法。
用具有正确语法的 mysqli 命令替换所有 mysql。如果需要,请在线检查 mysqli 文档..
例如 - 将 mysql_connect 替换为 mysqli_connect 以及其他 mysql 命令..
希望能解决您的问题。
关于php - 使用 PHP Ajax 代码在 MySQL 数据库中存储开/关按钮的值抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31891126/
据我所知,标准 jQuery“切换”功能在 jQuery mobile 中不起作用 - 这是正确的吗?如果是这样,还有其他有效的方法吗?我想做的就是打开和关闭“播放”按钮。所以按钮 ID 是“play
他们要求我提供一个“切换按钮”来打开和关闭集群有人可以帮助我实现集群的打开/关闭吗? 注意:加载超过30,000点 最佳答案 创建两层,一层有标记聚类,一层没有标记聚类,并将它们添加到传单控件中。例如
所以我想让我的 Python Gtk 小窗口有 2 个开关。当一个开关打开时,另一个开关关闭,反之亦然。我不太清楚如何控制这两个开关。如果有人能引导我走向正确的方向,我将不胜感激。 #!/usr/bi
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我为我的 android 应用程序集成了推送通知,我想为任何 android 手机/标签打开/关闭推送通知,任何人都可以帮助我... protected void onPostExecute(Blog
我遇到无法更改的问题 Switch运行时的 textOn/textOff 内容。这意味着,绑定(bind)到简单按钮(用于测试目的)的以下代码不起作用: private int _counter =
我正在开发一个应用程序来测试 iPhone 屏幕是关闭还是打开,我尝试了堆栈溢出中指定的加速度计代码,它在屏幕开启状态下运行良好,但是当我关闭屏幕时,加速度计没有停用。 所以我开始怀疑当屏幕关闭时加速
我想将前置闪光灯设置为自动闪光灯,因此前置摄像头不支持闪光灯,所以我必须将一个 View 设置为白色,以便它作为闪光灯使用,现在我的问题是如果用户设置了怎么办闪光模式自动?当我必须显示 Flash V
我有一个表,其中每隔一个表行都有一个类名“hideme”。在我制作的 css 文件中 .hideme { display:none} 隐藏行包含一个密码字段和一个按钮。在任何给定时间只能显示一个隐藏行
我正在尝试使用 css 切换复选框,使用开/关图像进行切换。但是它并没有发生,fiddle . I agree input[type=checkbox] { display:non
我正在为智能手机编写一个网站。我使用 javascript: navigator.geolocation.getCurrentPosition 来获取位置。 尽管如此,在执行此功能之前,我需要检测 G
如何在我的 Android 应用程序中以编程方式设置数据漫游开/关? 最佳答案 提前为重新打开一个死帖而道歉,但我已经通过调用这个可执行文件设法实现了它: su -c settings put glo
我正在用 java 编程,但我也可以采用 C++(甚至伪)代码,没问题。这是我的意思: 我有一个类似播放列表的东西,例如 List lsMyPlaylist .现在我想给用户洗牌的机会,然后再回到有序
我正在寻找最好的、最具可扩展性的方式来跟踪大量的开/关。开/关适用于项目,编号从 1 到大约 6000 万。 (在我的例子中,开/关是成员(member)的书是否被编入索引,这是一个单独的过程。) 开
我发现下面的代码可以以被动的方式做到这一点。 context.registerReceiver(this.ScreenOffReceiver, new IntentFilter(Intent.ACTI
我有一个脚本,我定期运行以使用 Applescript 打开/关闭灰度。它在 High Sierra 上运行良好,但当我在 Mojave 使用它时抛出异常。 tell application "Sys
如果我启动一个内联 Matplotlib 的 IPython Notebook,有没有办法随后绘制一个图形,以便它以“标准”、非内联的方式显示,而无需在没有内联命令的情况下重新加载笔记本? 我希望能够
如何使用Android中的CheckBoxPreference切换整个系统的声音,振动,数据连接和wifi? 我想在我的应用程序中正在运行 Activity 时禁用这些功能。 最佳答案 我想到了。 在
我想在我的网站上创建一个维护模式,我想放置一个只有管理员才能看到的按钮来打开/关闭维护模式。 这允许管理员继续查看网络,但其他访问者则不能。 我读过有关 catchAllRequest 的内容,创建一
如何检测客户端或服务器端 (ASP.NET) 的浏览器缓存设置。基本上尝试检测用户浏览器是否打开或关闭了缓存。如果关闭,我想将他们重定向到一个包含错误消息的页面,告诉他们打开它。这可能吗? 最佳答案
我是一名优秀的程序员,十分优秀!