Jump to content

is it possible to post php variable with javascript


Lisa23

Recommended Posts

hi is it possible to post a variable like this either with javascript or php

 

query.php

<?php
include("../../includes/config.php");
mysql_connect($db_address, $db_username, $db_password);mysql_select_db($db_name) or die(mysql_error());
$fid = $_GET['fid'];	
$fid = mysql_real_escape_string($fid);
$query10 = "SELECT * FROM films WHERE (film_id = '$fid')";	
$qry_result10 = mysql_query($query10) or die(mysql_error());
while($row10 = mysql_fetch_array($qry_result10))	
{	$urlfid="http://www.onfilm.biz/streaming/home/".$row10['client']."/".$row10['client_office']."/".$row10['filename'].".mp4";?>		
<a class="hofwhite14" href="#" onclick="loadNplay('<?php echo $urlfid; ?>')"><u></u>Property Film</u></a>
<?php	}mysql_close();
//EDIT 290510
?>

<script type="text/javascript">

var video= $urlfid;
$.post('indextest.php', {urlfid:video});

</script>

Link to comment
Share on other sites

basicaly i need the value of $urlfid from that query to go into a different page which is indextest.php

so it would be the query

<?php
include("../../includes/config.php");
mysql_connect($db_address, $db_username, $db_password);mysql_select_db($db_name) or die(mysql_error());
$fid = $_GET['fid'];	
$fid = mysql_real_escape_string($fid);
$query10 = "SELECT * FROM films WHERE (film_id = '$fid')";	
$qry_result10 = mysql_query($query10) or die(mysql_error());
while($row10 = mysql_fetch_array($qry_result10))	
{	$urlfid="http://www.onfilm.biz/streaming/home/".$row10['film_client']."/".$row10['film_client_office']."/".$row10['film_filename'].".mp4";?>		
<a class="hofwhite14" href="#" onclick="loadNplay('<?php echo $urlfid; ?>')"><u></u>Property Film</u></a>
<?php	}mysql_close();
//EDIT 290510
?>

<?php
echo $urlfid;
?>

 

so i would have something that would that would post the $urlfid to another page

does it make any sense

so i thought something like is that something possible?

<?php

POST $urlfid; TO indextest.php

?>

 

 

Link to comment
Share on other sites

ok i think i am doing right first of all the query is on a page film.php which i want to post into indextest.php

so this is the

film.php

<?php
include("../../includes/config.php");
mysql_connect($db_address, $db_username, $db_password);mysql_select_db($db_name) or die(mysql_error());
$fid = $_GET['fid'];	
$fid = mysql_real_escape_string($fid);
$query10 = "SELECT * FROM films WHERE (film_id = '$fid')";	
$qry_result10 = mysql_query($query10) or die(mysql_error());
while($row10 = mysql_fetch_array($qry_result10))	
{	$urlfid="http://www.onfilm.biz/streaming/home/".$row10['film_client']."/".$row10['film_client_office']."/".$row10['film_filename'].".mp4";?>		
<a class="hofwhite14" href="#" onclick="loadNplay('<?php echo $urlfid; ?>')"><u></u>Property Film</u></a>
<?php	}mysql_close();
//EDIT 290510
?>

<?php echo $_POST['urlfid'] ?>

and the indextest.php

<?php $urlfid = $_GET['urlfid'] 

echo $urlfid; ?>

is that right if so is not working for some reason?

Link to comment
Share on other sites

POST!!

 

indextest.php should be

 

<?php $urlfid = $_POST['urlfid'] 

echo $urlfid; ?>

 

if that doesnt work their is something wrong with your javascript.

 

1) $.post is jquery, make sure thats linked in.

2) also, make sure that you are initialising the jquery properly, bind it to something. a click, page load whatever.

3) also, you cannot just refresh the page open in another window, this is POST, if you want to see it by loading the page separately you will have to save it to a session/cookie or something.

Link to comment
Share on other sites

thats not jquery, thats javascript.

 

to progress look up jquery. (quick def: jquery is a library that make javascript easier. )

 

and look up what post and get are. (quick def: get takes variable from the url, post takes variable from a form)

Link to comment
Share on other sites

ok thanks i thats the problem i didnt want to post with a form wanted without

one more question if you know is there a way i can replace

var ajaxDisplay10 = document.getElementById('ajaxFilmLink');

with

var ajaxDisplay10 = document.getElementById($urlfid);

basicaly what i am trying to do if you see my webpage

http://www.estateagentsonfilm.co.uk/tv/bellway/indextest.php#

everytime you click on the image to load a new video each video i managed to get it to echo the filename but using ajax div and that query i've post previously but what i am trying to achive now is grab that url each time you click and put into a variable

any idea how i cn do that?

Link to comment
Share on other sites

Yeah thats the problem i have been learning php but not ajax but i've been asked to modify this script volunter work so i am trying to grasb a bit of ajax too

so at moment the ajax is like this

ajaxpage.js

var ajaxDisplay10 = document.getElementById('ajaxFilmLink');

and to display

indextest.php

<div id="ajaxFilmLink"></div>

which from what i read get element by id will display that data on that html div <div id="ajaxFilmLink">

which i dnt want to be dependable on a div id to echo the result

because i then try use that result like this on jwplayer videoplayer like this

 'file': '<?php echo <div id="ajaxFilmLink"></div>; ?>',

doesnt work

but from the code you gave are you saying it would be possible for me to just use it like

var ajaxDisplay10 = document.getElementById('<?php echo $urlfid ?>'); 

and display the result just like this

	 'file': '<?php echo $urlfid ; ?>',

is that right or ma i not making any sense?

 

 

so is that code that you gave me i can use it like this

 

Link to comment
Share on other sites

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.