Lisa23 Posted September 3, 2011 Share Posted September 3, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/246361-is-it-possible-to-post-php-variable-with-javascript/ Share on other sites More sharing options...
thewooleymammoth Posted September 3, 2011 Share Posted September 3, 2011 You may need to be a bit more specific on what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/246361-is-it-possible-to-post-php-variable-with-javascript/#findComment-1265114 Share on other sites More sharing options...
Lisa23 Posted September 3, 2011 Author Share Posted September 3, 2011 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/246361-is-it-possible-to-post-php-variable-with-javascript/#findComment-1265115 Share on other sites More sharing options...
JKG Posted September 3, 2011 Share Posted September 3, 2011 $.post('indextest.php', {urlfid:<?php echo urlfid; ?>}); get it on indextest.php by <?php echo $_POST['urlfid'] ?> Quote Link to comment https://forums.phpfreaks.com/topic/246361-is-it-possible-to-post-php-variable-with-javascript/#findComment-1265116 Share on other sites More sharing options...
Lisa23 Posted September 3, 2011 Author Share Posted September 3, 2011 and on the indextest.php to receive the variable is it? $_GET['urlfid'] which i then can echo on the indextest like <?php echo $urlfid; ?> am i on the right track?? Quote Link to comment https://forums.phpfreaks.com/topic/246361-is-it-possible-to-post-php-variable-with-javascript/#findComment-1265118 Share on other sites More sharing options...
JKG Posted September 3, 2011 Share Posted September 3, 2011 no you are posting it. so it needs to be <?php echo $_POST['urlfid'] ?> you can declare it again and echo like this <?php $urlfid = $_POST['urlfid'] echo $urlfid; ?> Quote Link to comment https://forums.phpfreaks.com/topic/246361-is-it-possible-to-post-php-variable-with-javascript/#findComment-1265119 Share on other sites More sharing options...
Lisa23 Posted September 3, 2011 Author Share Posted September 3, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/246361-is-it-possible-to-post-php-variable-with-javascript/#findComment-1265120 Share on other sites More sharing options...
JKG Posted September 3, 2011 Share Posted September 3, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/246361-is-it-possible-to-post-php-variable-with-javascript/#findComment-1265121 Share on other sites More sharing options...
Lisa23 Posted September 3, 2011 Author Share Posted September 3, 2011 jquery so you mean i should have the post inside the jquery like <script type="text/javascript"> <?php echo $_POST['urlfid'] ?> </script> and retrive inside the jquery too like this? <?php $urlfid = $_GET['urlfid']; echo $urlfid; ?> or not? Quote Link to comment https://forums.phpfreaks.com/topic/246361-is-it-possible-to-post-php-variable-with-javascript/#findComment-1265124 Share on other sites More sharing options...
JKG Posted September 3, 2011 Share Posted September 3, 2011 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) Quote Link to comment https://forums.phpfreaks.com/topic/246361-is-it-possible-to-post-php-variable-with-javascript/#findComment-1265126 Share on other sites More sharing options...
Lisa23 Posted September 3, 2011 Author Share Posted September 3, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/246361-is-it-possible-to-post-php-variable-with-javascript/#findComment-1265131 Share on other sites More sharing options...
JKG Posted September 3, 2011 Share Posted September 3, 2011 var ajaxDisplay10 = document.getElementById('<?php echo $urlfid ?>'); javascript and php are not the same language! here you are injecting the javascript with a php variable, you need the php tags. Quote Link to comment https://forums.phpfreaks.com/topic/246361-is-it-possible-to-post-php-variable-with-javascript/#findComment-1265133 Share on other sites More sharing options...
Lisa23 Posted September 3, 2011 Author Share Posted September 3, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/246361-is-it-possible-to-post-php-variable-with-javascript/#findComment-1265137 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.