PatrickLawler Posted February 15, 2013 Share Posted February 15, 2013 (edited) the first chunk of code is in my index.php file. I am trying to pass the $_SESSION['mes_id1'] variable into another php file called up.php and it will not get passed. the second chunk of code is the up.php file and the third chunk of code is my config.php file. any help is very much appreciated!!!!! thank you in advance!!!! index.php <?php session_id(); session_start(); mysql_connect("localhost", "FoleyHurley", "*******"); mysql_select_db("voting2"); ?> <div id="mipods" class="section2" style="display: none;"> <!-- assign mysql data rows to corresponding php variables --> <?php $sql = mysql_query("SELECT * FROM blogData ORDER BY id DESC"); $sql2=mysql_query("SELECT * FROM messages WHERE mod(mes_id,2) = 0 ORDER BY mes_id DESC"); $sql3=mysql_query("SELECT * FROM messages WHERE mod(mes_id,2) = 1 ORDER BY mes_id DESC"); while(($row = mysql_fetch_array($sql))&&($row2 = mysql_fetch_array($sql2))&&($row3 = mysql_fetch_array($sql3)) ){ $id = $row['id']; $title = $row['title']; $content = $row['content']; $category = $row['category']; $podcast = $row['podcast']; $datetime = $row['datetime']; $message1=$row2['msg']; $mes_id1=$row2['mes_id']; $totalvotes1=$row2['totalvotes']; $message2=$row3['msg']; $mes_id2=$row3['mes_id']; $totalvotes2=$row3['totalvotes']; $_SESSION['message1'] = $message1; $_SESSION['message2'] = $message2; $_SESSION['mes_id1'] = $mes_id1; $_SESSION['mes_id2'] = $mes_id2; $_SESSION['totalvotes1'] = $totalvotes1; $_SESSION['totalvotes2'] = $totalvotes2; ?> <?php // variable used to display file name of $podcast without the extension $noext = $podcast; $echodub = rawurlencode($podcast); // code to display $noext without the file extension $info = pathinfo($noext); $noext_name = basename($noext,'.'.$info['extension']); ?> <!-- echo php variables in html format, in a table with the class of "podcast" --> <table class="podcast" border="1"> <tr> <td class="title"> <?php echo $title; ?> </td> <td class="timeandcategory"> <?php echo $datetime; ?> <br> <?php echo $category; ?> <?php echo $_SESSION['mes_id1']; ?> <?php echo $_SESSION['mes_id2']; ?> <?php echo session_id(); ?> </td> </tr> <tr> <td class="content"> <?php echo $content; ?> </td> <td class="myfblike"> <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://localhost:8888/blog1/index.php#<?php echo $noext; ?>" data-counturl="http://localhost:8888/blog1/index.php#<?php echo $noext; ?>" data-text="listen to SD's new podcast! www.sportdebaters.com#<?php echo $noext; ?> @SDebaters " data-related="SDebaters" data-hashtags="SDebaters">Tweet</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> <span class='st_fblike_large' displayText='Facebook Like'></span><br> <span class='st_facebook_large' displayText='Facebook'></span><br> <span class='st_twitterfollow_large' displayText='Twitter Follow'></span><br> <span class='st_pinterest_large' displayText='Pinterest'></span><br> <span class='st_email_large' displayText='Email'></span><br> <span class='st_sharethis_large' displayText='ShareThis'></span><br> </td> </tr> <tr> <td class="audio"> <!--echo the audio file --> <ul class="playlist"> <li><a href="<?php echo"uploads/$podcast"; ?>"><?php echo"$noext_name"; ?></a></li> </ul> <!--<div id="sm2-container"> (I don't have an SM2 flash movie... but lets save this for later but for now I will comment out the div this is contained in also....) SM2 flash movie goes here </div> --> </td> <td> <div id="main"> <div id="left"> <span class='up'><a href="" class="vote" id="<?php echo $_SESSION['mes_id1']; ?>" name="up"><img src="up.png" alt="Down" /></a></span><br /> <?php echo $_SESSION['totalvotes1'] ?><br /> <!--<span class='down'><a href="" class="vote" id="<?php echo $mes_id1; ?>" name="down"><img src="down.png" alt="Down" /></a></span>--> </div> <div id="message"> <?php echo $_SESSION['message1'] ?> </div> <div class="clearfix"></div> </div> <div id="main"> <div id="left"> <!--<span class='up'><a href="" class="vote" id="<?php echo $mes_id2; ?>" name="up"><img src="up.png" alt="Down" /></a></span>--><br /> <?php echo $_SESSION['totalvotes2'] ?><br /> <span class='down'><a href="" class="vote" id="<?php echo $_SESSION['mes_id2']; ?>" name="down"><img src="down.png" alt="Down" /></a></span> </div> <div id="message"> <?php echo $_SESSION['message2'] ?> </div> <div class="clearfix"></div> </div> </td> </tr> </table> <br> <?php } ?> </div> up.php <?php session_start(); include("config.php"); $ip=$_SERVER['REMOTE_ADDR']; $ip_sql=mysql_query("select ip_add from Voting_IP where mes_id_fk='".$_SESSION['mes_id1']."' and ip_add='$ip'"); $count=mysql_num_rows($ip_sql); $ip_sql2=mysql_query("select ip_add from Voting_IP where mes_id_fk='".$_SESSION['mes_id2']."' and ip_add='$ip'"); $count2=mysql_num_rows($ip_sql2); if($count==0 && $count2!=0) { $sql = "update Messages set totalvotes=totalvotes+1 where mes_id='".$_SESSION['mes_id1']."'"; mysql_query( $sql); $sql_in = "insert into Voting_IP (mes_id_fk,ip_add) values ('".$_SESSION['mes_id1']."','$ip')"; mysql_query( $sql_in); $sql = "update Messages set totalvotes=totalvotes-1 where mes_id='".$_SESSION['mes_id2']."'"; mysql_query( $sql); $sql_in = "DELETE FROM Voting_IP WHERE mes_id_fk='".$_SESSION['mes_id2']."'"; mysql_query( $sql_in); } else if($count==0 && count2==0) { $sql = "update Messages set totalvotes=totalvotes+1 where mes_id='".$_SESSION['mes_id1']."'"; mysql_query( $sql); $sql_in = "insert into Voting_IP (mes_id_fk,ip_add) values ('".$_SESSION['mes_id1']."','$ip')"; mysql_query( $sql_in); } ?> config.php <?php $mysql_hostname = "localhost"; $mysql_user = "FoleyHurley"; $mysql_password = "******"; $mysql_database = "voting2"; $prefix = ""; $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database"); mysql_select_db($mysql_database, $bd) or die("Could not select database"); ?> Edited February 15, 2013 by PatrickLawler Quote Link to comment https://forums.phpfreaks.com/topic/274514-cant-pass-session-variable/ Share on other sites More sharing options...
PatrickLawler Posted February 15, 2013 Author Share Posted February 15, 2013 (edited) the up.php file seems to be reading $_SESSION['mes_id1'] as the same value in each of the links in the table in index.php. when it should be reading the different values of mes_id from my database. but when I echo $_SESSION['mes_id1'] in the table in index.php, the correct $_SESSION['mes_id1'] value is echoed in each table. so It looks like something is wrong in the up.php file, or something is wrong in getting the $_SESSION['mes_id1'] to be passed to up.php Edited February 15, 2013 by PatrickLawler Quote Link to comment https://forums.phpfreaks.com/topic/274514-cant-pass-session-variable/#findComment-1412568 Share on other sites More sharing options...
PatrickLawler Posted February 15, 2013 Author Share Posted February 15, 2013 (edited) any help would still be greatly appreciated.... in trying to debug my code and I figured out that in the up.php file, $_SESSION['mes_id1'] is only equal to the last row that was queried in index.php...... it displays the correct value in the tables but when the query is finished, $_SESSION['mes_id1'] is only equal to the last value queried. i need each link in my table to set the $_SESSION['mes_id1'] variable to it's corresponding value and pass that along to up.php $(function() { $(".vote").click(function() { var id = $(this).attr("id"); var name = $(this).attr("name"); var dataString = 'id='+ id ; var parent = $(this); if(name=='up') { $(this).fadeIn(200).html(''); $.ajax({ type: "POST", url: "up.php", data: dataString, cache: false, success: function(html) { parent.html(html); } }); } else { $(this).fadeIn(200).html(''); $.ajax({ type: "POST", url: "down.php", data: dataString, cache: false, success: function(html) { parent.html(html); } }); } }); }); Edited February 15, 2013 by PatrickLawler Quote Link to comment https://forums.phpfreaks.com/topic/274514-cant-pass-session-variable/#findComment-1412646 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.