Solved

Change database value without page-load?

Posted on 2015-01-14
4
149 Views
Last Modified: 2015-01-19
Hi,

I got a page which contain a lot of rows from a table.
The db-table got a "locked" column (ENUM "0","1").

I display a lock/unlock image to the user, based on the value of this column.
Is it possible to change db value and replace image without a page-load?
0
Comment
Question by:kgp43
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 350 total points
ID: 40548688
The "without a page load" part seems to imply that you would make an AJAX request.  The short answer is "yes, you can do that."  There is an article here that gives the design pattern of a PHP / jQuery AJAX implementation.   It shows how to get around the "page load" issues and still accomplish back-and-forth communication with the server via the standard request/response.
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html

More about the nature of HTTP:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/A_11271-Understanding-Client-Server-Protocols-and-Web-Applications.html
0
 
LVL 2

Assisted Solution

by:Elxn
Elxn earned 150 total points
ID: 40551404
Got a version of this working on my site.  See it here: http://girlzunderground.com/ee.html

Do you need the code explained to you?

You'll need to change all the image names in the javascript code and you'll also need to change what page the ajax call is made to.

Just change the actual image name, you shouldn't have to worry about the path as long as the two images (lock.png / unlock.png) are in the same folder.

Also, you see the function accepts the parameter "id"; this is posted to the page as well--you might want to put the id of the record in the onclick event in the image tag (right now its 1, 2, or 3) and this value will get sent to your page as well.  THought you might want that.
0
 

Author Closing Comment

by:kgp43
ID: 40557786
Thank's alot guys, exactly what I was looking for :)
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40557803
Thanks for the points and best of luck with your project, ~Ray
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question