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

Posted on 2011-10-14
Last Modified: 2013-12-12
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

Question by:corterp
    LVL 13

    Expert Comment

    by:Hugh McCurdy
    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.

    You might also want to investigate JQuery
    LVL 33

    Expert Comment

    Can you not just use PHP to add the data via a form?
    LVL 13

    Expert Comment

    by:Hugh McCurdy
    Good question imnorie.  If that's acceptable then he/she could save a lot of time.

    Author Comment

    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.
    LVL 13

    Expert Comment

    by:Hugh McCurdy
    AJAX is a good way to replace part of a page without having to reload the entire page.
    LVL 13

    Accepted Solution

    Use AJAX for submitting data via PHP.
    Otherwise update hidden form field using javascript and then submit form data using javascript.

    Author Comment

    Thank you,

    I have a lot to learn.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Suggested Solutions

    Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
    Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
    In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
    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)

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now