Jump to content
asai

Data from a table

Recommended Posts

$POST should be $.post (call jquery $.post function)

 

"Hva skjer her?"  should be "text" (tell the function the response is plain text)

Share this post


Link to post
Share on other sites

Ok, now we are getting closer. When I click the link, theres a empty popup box. When I click OK the movie is shown.

But theres nothing updating... :

 

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

 

I know, I am a bit slow... :tease-03:

Share this post


Link to post
Share on other sites

Ok, now I am starting to understand this.  :happy-04:

One small thing: I suspect that the update.php file never runs or the filename parameter isn't correct.

 

Is this line correct:

$filename = $_POST['filename'];

??

Share this post


Link to post
Share on other sites

That line should be OK, the filename is being sentin $_POST['filename'].

 

You could test it by putting

 

exit ($filename);

 

directly after that line. The filename should appear in the alert() box.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

You are passing the string "filename" instead of the variable filename

Share this post


Link to post
Share on other sites

{filename: "filename"}

is the opposite of what it should be, as Barand pointed out. Compare his original code to what you have.

Share this post


Link to post
Share on other sites

Theres something not going right here...

I have placed the script inside the movies.php file. Is the place inside the file important?

The update.php file is never run.

The link opens the file, but not from within the script.  :  :

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

One simple question:

How can i make $url be a combination of the variable $filename and the text "/alldaymovies/" ?

 

Have tried this but it doesn't work:

$url = "/alldaymovies/" $filename;

Share this post


Link to post
Share on other sites

$url = "/alldaymovies/" . $filename; //you need to concatenate the variable
$url = "/alldaymovies/$filename"; //or put it in the quotes
Edited by CroNiX

Share this post


Link to post
Share on other sites

Fantastic! Thanks for quick reply.

One final question: Is there a way to open this url in a new window from within the php file without having to click a link or button?

Something like this:

window.open($url);

??

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

 

 

window.open($url);

 

That is javascript.

 

Repeat to yourself several hundred times, or until it sinks in, "PHP runs on the server, javascript runs on the client"

  • Like 1

Share this post


Link to post
Share on other sites

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>

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

 

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

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.