[英]inline update in mysql using jquery/php
I'm performing CRUD
oprations using JQuery/Ajax and php/MySQL
我正在使用
JQuery/Ajax and php/MySQL
执行CRUD
操作
i'm able to insert/select
and delete
data but i gotta stuck in edit/update. 我能够
insert/select
和delete
数据,但我必须卡在编辑/更新中。 im pulling data into text box when i click on edit button but after editing when i click on save button unable to update in mysql db!! 我点击编辑按钮时将数据拉入文本框,但是当我点击保存按钮后编辑后无法在mysql数据库中更新!
Any help is Appreciated Thanks 任何帮助表示感谢
html code HTML代码
<span class="noedit name" idl='<?php echo $row->id;?>'>
<?php echo $row->url;?>
</span>
<input id="url1" name="url1" class="form-control edit name url1" value="<?php echo $row->id;?>"/>
<a ide='<?php echo $row->id;?>' id="edit" class='editOrder' href="#" style="display:block-inline;">EDIT</a>
<a idu='<?php echo $row->id;?>' id="update" class='update saveEdit' href='#' style='display:none;'>SAVE</a>
<a idc='<?php echo $row->id;?>' id="cancel" class='cancelEdit edit' href='#' style='display:none;'>CANCEL</a>
Jquery code jQuery代码
$('body').delegate('.edit','click',function(){
var IdEdit = $(this).attr('ide');
alert(IdEdit);
$.ajax({
url:"pages/feeds.php",
type:"post",
data:{
editvalue:1,
id:IdEdit
},
success:function(show)
{
$('#id').val(show.id);
$('#url1').val(show.url);
}
});
});
$('.update').click(function(){
var id = $('#id').val()-0;
var urls = $('#url1').val();
$.ajax({
url:"pages/feeds.php",
type:"post",
async:false,
data:{
update:1,
id:id,
upurls:urls
},
success:function(up)
{
$('input[type=text]').val('');
showdata();
},
error:function(){
alert('error in updating');
}
});
});
PHP Code PHP代码
if(isset($_POST['editvalue']))
{
$sql = "select * from test where id='{$_POST['id']}'";
$row = mysql_query($sql);
$rows = mysql_fetch_object($row);
header("Content-type:text/x-json");
echo json_encode($rows);
exit();
}
if(isset($_POST['update']))
{
$sql = "
update test
set
url='{$_POST['upurls']}'
where id='{$_POST['id']}'
";
$result = mysql_query($sql);
if($result)
{
//alert('success');
echo 'updated successfully';
}
else
{
//alert('failed');
echo 'failed to update';
}
}
I don't see an #id input in your code. 我在您的代码中看不到#id输入。 is it there?
在那吗
I think the problem is here. 我认为问题就在这里。
If this input exists, use the following tips: 如果存在此输入,请使用以下提示:
Check if all values (id, url) are sended to your PHP script. 检查是否所有值(id,url)都已发送到您的PHP脚本。
You can use console.log
in Javascript or print_r
, var_dump
functions in PHP. 您可以在Javascript中使用
console.log
或在PHP中使用print_r
或var_dump
函数。
Change 更改
$('.update').click(function(){
to 至
$('.saveEdit').click(function(){
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.