0

Is there an easy way to update this query using javascript or something similar ? I am using a simple cache that isn't updating this query:

$query_rs_update = sprintf("UPDATE cute_news SET views = views+1 WHERE id = %s", GetSQLValueString($colname_DetailRS1, "int"));
$rs_update = mysql_query($query_rs_update) or die(mysql_error());

Trying to get it to record views, even when the cache is on ?

Thanks NINJAS!!!

2
  • 1
    You could use AJAX. But, not sure if I get what you mean by... emm.. still don't get. Commented Sep 2, 2013 at 14:34
  • All I am doing is updating a record in a MYSQL table ? Commented Sep 2, 2013 at 14:35

1 Answer 1

2

Typically, Javascript does not interact directly with a database. The good thing about this is that a hacker can't abuse your system by exploiting publicly visible code.

What you'll want to do is create a script that can be called from javascript using AJAX (POST) and that will perform any logic you need. In your case, it looks like your AJAX call will pass along a news article id.

Also, I recommend using prepared statements or another protected query technique so that your code isn't SQL injectable (like PDO prepared statements).

Sign up to request clarification or add additional context in comments.

2 Comments

Interesting information! THanks! Any chance you could help with the code like I asked ?
pastebin.com/Uh2YBhLH Here's some Javascript for using jQuery post. I included links to php PDO because that's already well-documented. jQuery is also well documented at the link I gave.

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.