Jump to content

shout box / iframe / sql / insert data problem session


shaunak1234

Recommended Posts

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'] . "&nbsp:</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? :(:confused:

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?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.