PDA

View Full Version : Ajax Mysql Php




Vitaminwater
Jan 23, 2010, 04:45 PM
I'm looking for an Ajax tutorial online that uses php and a mysql database as the backend. What i want to accomplish is have a link on my website and every time someone clicks it, it increments by one, and stops them from clicking the link again.

I can do the IP logging to stop repeat voters fairly easily, however, i'm most confused with the way ajax and mysql interact.

Thanks



angelwatt
Jan 23, 2010, 05:34 PM
AJAX and MySQL cannot interact directly. An AJAX call would call a PHP script, that script would interact with MySQL, and then may report back to the web page. Most AJAX tutorials that call a PHP function should cover the basics of what you need.

JavaScript libraries like jQuery and MooTools have made AJAX calls pretty easy so you may want to look into them. It would be easier to give advice once you get started. It shouldn't be very hard to find a tutorial.

Bostonaholic
Jan 23, 2010, 06:53 PM
^ What he said +

I'm a beginner with PHP as well but would it be better to use cookies ($_COOKIE) as opposed to IP logging to stop repeat voters? Perhaps angelwatt or SrWebDeveloper can chime in?

Maxington
Jan 23, 2010, 08:07 PM
A good resource for info is: http://www.w3schools.com/

angelwatt
Jan 23, 2010, 09:15 PM
I'm a beginner with PHP as well but would it be better to use cookies ($_COOKIE) as opposed to IP logging to stop repeat voters?

Using IP would probably be a bit more consistent than cookies. If a person used multiple browsers on their machine, each browser could make a vote whereas their IP would be the same so they would only allow a single vote on that criteria. A user could also delete cookies or have their browser set to not accept them. It may also not work for those using private browsing mode, though I haven't looked into that much to see its impact.

The IP isn't full-proof either, but takes more effort on the user's part. The only reasonably full-proof method would require users to have an account and only let a user vote once, which would be enforced using the account management. That only works without a user system though.

Bostonaholic
Jan 23, 2010, 09:28 PM
Using IP would probably be a bit more consistent than cookies. If a person used multiple browsers on their machine, each browser could make a vote whereas their IP would be the same so they would only allow a single vote on that criteria. A user could also delete cookies or have their browser set to not accept them. It may also not work for those using private browsing mode, though I haven't looked into that much to see its impact.

The IP isn't full-proof either, but takes more effort on the user's part. The only reasonably full-proof method would require users to have an account and only let a user vote once, which would be enforced using the account management. That only works without a user system though.

That makes sense. I was trying to weigh the pros and cons for both. I too am implementing a rating system for my blog. Instead of using cookies, maybe I'll attach an IP to each rating in the DB. If the IP already exists, do an UPDATE as opposed to INSERT so that readers can change their rating...hmm, but now I'm trying to think of how this will work with my current database entities. Something to think about.

savar
Jan 24, 2010, 11:02 AM
I'm looking for an Ajax tutorial online that uses php and a mysql database as the backend. What i want to accomplish is have a link on my website and every time someone clicks it, it increments by one, and stops them from clicking the link again.

I can do the IP logging to stop repeat voters fairly easily, however, i'm most confused with the way ajax and mysql interact.

Thanks

"AJAX" is a bogus term. I wish people would stop using it. It literally stands for "Asynchronous Javascript And XML". So if you're not using XML, its not AJAX.

I prefer to simply call this "asynchronous behavior", meaning that you are doing things on the client side to refresh data on the page without doing a full page refresh. "XHR" is also a reasonable term, since it describes the name of the API which you use to achieve this behavior. Unfortunately, the X in XHR stands for "XML", so once again its kind of a bogus term.

Anyway, IP addresses are going to be better than cookies, since cookies can be manipulated very easily. But keep in mind that many users share IP addresses -- for example one IP address for their entire home network. Same goes for many small businesses. So your users might be frustrated or surprised to discover that their vote has been changed!

Authentication doesn't really solve the problem either since users can create multiple accounts. But as long as you have a good CAPTCHA, you could at least prevent large scale, automated vote rigging.