Jump to content

Recommended Posts

The function(data). What is? Should't this be defined somewhere?

No, see the documentation for jQuery's $post function. It's the "success" callback function and is already defined as part of $post.

Edited by CroNiX

Something is still missing here:

 

I have tried this:

function playVideo(url, filename)
{
    $.post( "update.php", {filename: "filename"})
  .done(function( data ) {
    alert( "Data loaded: " + data );
  });
}

The output from the alert is "filename"

Not the actual filename i want.

Hi again,

I have come a little further with my project.

A small change from earlier, but now the update works. Then change is that I haven't a link, but instead uses a button.

One small thing that doesn't work, that is the movie is not run.

I am not sure how and where to put it.

Heres my movies.php file:

<html>
<head>
<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<?php

include 'combo.php';
include 'config.php';
include 'opendb.php';

$ndate = $_POST['ndate'];

$result = mysql_query("SELECT *
            FROM DayMovie 
            WHERE FileDate LIKE '$ndate%' ORDER BY FileDate DESC") 
or die(mysql_error());  
echo "<table border='0'>";
echo "<tr> <th>Dato</th><th>Visninger</th><th>Handling</th></tr>";
while($row = mysql_fetch_array( $result )) {
	echo "<tr><td>";
	echo date('d.m.Y', strtotime($row['FileDate']));
	echo "</td><td>";
	echo $row['Counter'];
	echo "</td><td>";
    	
?>

   <form name="form" method="POST" action="update.php">
     <input name='filename' type='hidden' value=<?php echo $row['FileName'];?>>
	 <input name='url' type='hidden' value=<?php echo "alldaymovies/{$row['FileName']}"?>>
     <input type="submit"  value="Se film">
   </form>

<?php
}
   echo "</td></tr>";
echo "</table>";

include 'closedb.php';
?>

</html>

From here I post both filename and url to update.php

update.php looks like this:

<html>
<head>
<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<?php

include 'config.php';
include 'opendb.php';

$filename = $_POST['filename'];
$url      = $_POST['url'];

$result2 = mysql_query("UPDATE DayMovie SET Counter=Counter+1 WHERE FileName='$filename'") 
or die(mysql_error());

include 'closedb.php';

?>

Right now I am not using the url.

Theres 2 things I would like to happen from here:

1. The movie opens from the url in a new window.

2. The update.php returns to movies.php

 

Is this possible and how?

This is now my update.php

<html>
<head>
<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<?php

include 'config.php';
include 'opendb.php';

$filename = $_POST['filename'];

$result2 = mysql_query("UPDATE DayMovie SET Counter=Counter+1 WHERE FileName='$filename'") 
or die(mysql_error());

include 'closedb.php';

$url = "http://81.166.2.19/alldaymovies/$filename";
window.open($url);

?>

</html>

The data is database is updated, but no window opens with the url. What's missing?

Sorry if I am a little slow...  :-\

From this button is there a way to call a javascript function to open a new window from the url? :

<form name="form" method="POST" action="update.php">
     <input name='filename' type='hidden' value=<?php echo $row['FileName'];?>>
     <input type="submit"  value="Se film">
   </form>

I haven't read back through all of the pages of posts so sorry if this has been coverered - but it seems more sensible to not use forms, and just put your viewing counter processing code on the page of wherever you're hosting the movie itself

 

Just loop out a set of url's instead of submit buttons

<?php

while($row = mysql_fetch_array( $result )) {

$output.= "<a href='alldaymovies.php?filename=$row[filename]' target='_blank'>$row['filename']</a>";
$output.= "<br>";

}

echo $output;

The use of '_blank' forces a new window to be opened in the browser.

 

Then at the top of the actual movie page...

$filename = $_GET['filename'];


$result2 = mysql_query("UPDATE DayMovie SET Counter=Counter+1 WHERE FileName='$filename'") 
or die(mysql_error());

you need to escape $filename as it's open to SQL injection

 

Sorry if I am a little slow...  :-\

From this button is there a way to call a javascript function to open a new window from the url? :

<form name="form" method="POST" action="update.php">
     <input name='filename' type='hidden' value=<?php echo $row['FileName'];?>>
     <input type="submit"  value="Se film">
   </form>

 

You would do it in the function on return of the ajax response as you have been shown in reply #49

http://forums.phpfreaks.com/topic/294097-data-from-a-table/page-3?do=findComment&comment=1504950

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.