Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

Getting Javascript into PHP, anyone know how or have ideas? Please help

I am trying to make it where if someone clicks on a movie, I want to enter inter a database what movie how many times it has been played and by who.  Does anyone have any ideas?
<script type="text/javascript">
	flowplayer("player1", "swf/flowplayer-3.2.7.swf", {
		clip: { 
			autoPlay: true,
			autoBuffering: true
	  // get all links that are inside div#clips 
		var links = document.getElementById("clips").getElementsByTagName("a"); 
	// loop those links and alter their click behaviour 
	for (var i = 0; i < links.length; i++) {
		links[i].onclick = function() { 
		document.getElementById("Playing").innerHTML = this.getAttribute("title");
            $dt = date('Y-m-d H:i:s');
			mysql_query("INSERT INTO WatchedBy (User, Date, Movie)
            VALUES ('$Username', '$dt', '$Movie')"); 
			// play the clip specified in href- attribute with Flowplayer 
			// by returning false normal link behaviour is skipped 
			return false;


Open in new window

1 Solution
Hugh McCurdyCommented:
It sounds like you are trying to "call" PHP from JavaScript.   Is that correct?  If so, you can't (using this method).  PHP completely finishes running before JavaScript even starts.

What might work for you instead is an AJAX approach.  http://www.w3schools.com/ajax/default.asp

You might also want to investigate JQuery   http://www.w3schools.com/jquery/default.asp
NorieData ProcessorCommented:
Can you not just use PHP to add the data via a form?
Hugh McCurdyCommented:
Good question imnorie.  If that's acceptable then he/she could save a lot of time.
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

corterpAuthor Commented:
What happens is I use php to pull items from a database and create a list so a person can select an item that will then use flowplayer to show the selected item.

But I would like to be able to have that selection saved.

They are able to select one home movie to another without having to load a new page.

I will look into the AJAX and jQuery also.

Thank you.
Hugh McCurdyCommented:
AJAX is a good way to replace part of a page without having to reload the entire page.
Abhijeet RananawareWeb & Mobile DeveloperCommented:
Use AJAX for submitting data via PHP.
Otherwise update hidden form field using javascript and then submit form data using javascript.
corterpAuthor Commented:
Thank you,

I have a lot to learn.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now