0

I want to update data where in mysql database using ajax and php.

HTML

<td><input type="text" class="event" name="title<?php echo $row['id']?>" id="title_id_<?php echo $row['id']?>" value="<?php echo $row['title']?>" disabled/></td>
            <td><input type="datetime" class="event" name="start<?php echo $row['id']?>" id="start_id_<?php echo $row['id']?>" value="<?php echo $row['start']?>" disabled/></td>
            <td><input type="datetime" class="event" name="end<?php echo $row['id']?>" id="end_id_<?php echo $row['id']?>" value="<?php echo $row['end']?>" disabled/></td>
            <td><div class="edit_wrapper"><a href="#" class="edit_button" id="edit-<?php echo $row['id'] ;?>"><img       src="http://icons.iconarchive.com/icons/custom-icon-design/flatastic-1/24/edit-icon.png"/></a></td>
            <td><div class="up_wrapper"><a href="" class="up_button" id="up-<?php echo $row['id'] ;?>"><img       src="http://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/24/Actions-svn-update-icon.png"/></a></td>
            <td><div class="del_wrapper"><a href="" class="del_button" id="del-<?php echo $row['id'] ;?>"><img       src="http://icons.iconarchive.com/icons/hopstarter/button/24/Button-Delete-icon.png"/></a></td>

jQuery Ajax Code

$('.up_button').click(function(){
    var btnid=this.id;
    btnid=btnid.replace(/\D/g, '');
    btnid=parseInt(btnid, 10);
    var e_title=$('#title_id_'+btnid).val();
    var e_start=$('#start_id_'+btnid).val();
    var e_end=$('#end_id_'+btnid).val();

    $.ajax({
        url: 'event_update.php',
        data:{'title':e_title , 'id':btnid , 'start':e_start, 'end': e_end},
        type: "POST",
        success: function() {
            alert("Güncelleme başarılı.");
        }
   });


});

Here My PHP Code(event_update.php)

<?php
include_once("config.php");
$id = $_POST['bid'];
$title = $_POST['title'];
$start = $_POST['start'];
$end = $_POST['end'];
mysql_query("UPDATE evenement SET title=$title,start=$start,end=$end WHERE id=$id"))
mysql_close($connecDB);
?>

But I Couldnt update data.Can you help?

4
  • Is it giving any error..?? If ur getting any fatal error I think ur missing ;(semi colon) here _sql_query("UPDATE evenement SET title=$title,start=$start,end=$end WHERE id=$id"))_<-- here Commented Apr 14, 2014 at 11:10
  • I had realize this. ANd I fixed.But this isnt help me. Commented Apr 14, 2014 at 11:12
  • Are you sure it's not updating ? Did you look into the DB ? Or make a page refresh ? As you use Ajax the page is not refreshing by itself.. Is the alert showing ? Commented Apr 14, 2014 at 11:12
  • $_POST['bid'] should be $_POST['id'] correct? Commented Apr 14, 2014 at 12:35

1 Answer 1

1

replace your query line by this, any non numeric entity must be enclosed.

   mysql_query("UPDATE evenement SET title='$title',start='$start',end='$end' WHERE id='$id'"))
Sign up to request clarification or add additional context in comments.

2 Comments

You should also add that mysql_* functions are deprecated and use PDO or MySQLi
Ok Everyone.I had fixed problem using php PDO class.I didnt found mistake which I made in previous mysql query.But Now everything is ok.Thank you All of you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.