shaunak1234 Posted July 9, 2011 Share Posted July 9, 2011 H there, I have an login page where after login the user can see Welcome, user. echo ("Welcome, " . $_SESSION['myusername']); this is the code to display it.. It works fine.. but in the same page I have an iframe displaying a shoutbox so whenever a person is logged in he can type a text in the shout box and submit it. this submitted data gets added to an SQL database but however I am not able to add corresponding user's name (who made that shout) in the SQL database. <?php $con = mysql_connect("localhost","root","*****"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("shout", $con); $result = mysql_query("SELECT * FROM shouts "); echo "<table border='0' cellpadding='5' cellspacing='0'> "; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td valign='top'>" . $row['name'] . " :</td>"; echo "<td>" . $row['shout'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> <?php $con = mysql_connect("localhost","root","*****"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("shout", $con); $name= $_SESSION['myusername']; $shout=$_POST['shout']; if (!$shout) { die (''); } session_start(); if(!session_is_registered(myusername)){ die ('You need to login first'); } echo $_SESSION["myusername"]; mysql_query("INSERT INTO shouts (name, shout) VALUES('$name' ,'$shout') ") or die(mysql_error()); ?> when I type in the text and click on shout it displays the message "you need to log...." in the shoutbox.. What Did I do wrong? Quote Link to comment https://forums.phpfreaks.com/topic/241511-shout-box-iframe-sql-insert-data-problem-session/ Share on other sites More sharing options...
QuickOldCar Posted July 9, 2011 Share Posted July 9, 2011 An iframe is a totally different page and will not retain the iframes parent pages information. You will have to do the script on the iframes source page for username. Can you not include() this? Quote Link to comment https://forums.phpfreaks.com/topic/241511-shout-box-iframe-sql-insert-data-problem-session/#findComment-1240617 Share on other sites More sharing options...
shaunak1234 Posted July 10, 2011 Author Share Posted July 10, 2011 :'( Actually I am new to sql and php so can you please explain a bit? Quote Link to comment https://forums.phpfreaks.com/topic/241511-shout-box-iframe-sql-insert-data-problem-session/#findComment-1240740 Share on other sites More sharing options...
shaunak1234 Posted July 10, 2011 Author Share Posted July 10, 2011 Hey I tried that but it is showing me my index.php in the I frame which I used in the include function Quote Link to comment https://forums.phpfreaks.com/topic/241511-shout-box-iframe-sql-insert-data-problem-session/#findComment-1240742 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.