Jump to content

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?

 

 

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.