Hi, and thanks for the help. the server side code is above. It seems to be correct. I guess the JS isn't working correct since there is no new connection as I see in the status bar. Nothing happens when I click the link.
Thanks for the code Andreas! I am sorry but I can understand it in detail. This is only for changing the image? But where and how can I integrate it into my code? And where can I update the DB? Hope you can help me little bit more :-) Thanks a million! On 14 Sep., 22:34, "Andras Kende" <[EMAIL PROTECTED]> wrote: > Hello, > > I have this for a toggling, debug with firebug so you could see whats > happening: > > jQuery(document).ready(function() { > > jQuery("a.status").unbind("change"); > jQuery("a.status").click(function(){ > var p = this.firstChild; > if (p.src.match('icon_1.png')) { > jQuery(p).attr({ src: "/img/icon_0.png", alt: "Activate" });} else { > > jQuery(p).attr("src","/img/icon_1.png"); > jQuery(p).attr("alt","Deactivate");}; > > jQuery.get(this.href + "?" + new Date().getTime() ); > return false;} > > ); > > } > > ) > > <td class="change"><a href="/admin/favorites/changestatus/5/favorite/" > class="status"><img src="/img/icon_0.png" alt="" /></a></td> > > Andras Kendehttp://www.kende.com/ > > On Sun, Sep 14, 2008 at 7:36 AM, suntrop <[EMAIL PROTECTED]> wrote: > > > I am sorry if this was posted twice! > > > ----------------------------------------------------------------------------------- > > > Hi, > > > I have a list of users that I pull out of a MySQL DB. Some are > > "favorite" users marked with a star. > > Now I want to change the state "is favorite/is not favorite" quickly > > with a click on the star image, and the image should turn directly to > > its state yellow(is favorite) or grey(is not favorite). > > > This is how the link and image looks like: > > <a href="{$user.id}" class="makeFavorite" id="makeFavorite-{$user.id}" > > title="Save as favorite"><img src="images/{if $user.favorit == > > 1}favorites.png{else}favorites2.png{/if}" width="16" height="16" > > alt="" /></a> > > > The JS look like this: > > // Make Favorite > > $('.makeFavorite').click(function() { > > $.ajax({ > > type: "POST", > > url: "make_favorite.php", > > data: "id=19", > > success: function(msg) { > > alert('Data saved: ' + msg); > > } > > }); > > return false; > > }); > > > The PHP: > > <?php > > …mysql connect … > > $sql = "UPDATE table SET favorite='1' WHERE id=$_POST[id]"; > > > mysql_query($sql); > > > echo 'My Msg: id is: ' . $_POST['id']; > > ?> > > > But unfortunately it doesn't work :( > > The Msg says "My Msg: id is 19" but the state in the DB won't update. > > > Since this is the very first time I'm dealing with AJAX it is a quite > > big thing for me :-) > > > What is wrong with the code above? And how can I change the image > > directly without reloading the page? > > > Hope you get what I want to do and can help me. Thanks!