Hi,I made a status for my site and all I need to do now is echo the username session,but when I do it,it doesn't work I would like to see an example of what I do to see what I did wrong.
The script is.
<?php
session_start();
?>
some html
<?php
include("connect.php");
$session=$_SESSION['username'];
if($_POST['submit'])
{
(skipped to inserting)
$sql="INSERT INTO status(Msg)VALUES('".$_POST['msg']."')";
$query=mysql_query($sql);
}
?>
What exactly happens when you try to echo the $session variable?
I think I see the problems with your file.
Try something like this:
<?php
session_start();
include 'connect.php';
$session=$_SESSION[username];
?>
[[Some html]]
Also, you should set up so that the data inserts the current user's name with each post, otherwise your status will display every post as having been made by the person viewing the page.
Set your form up like this:
<form method="post" action="">
<textarea name="msg" value="" rows="4" cols="15" type="text"></textarea>
<input type="submit" name="submit" value="Post"/>
</form>
(Also, use isset for form submission:)
<?php
//get user info
$stuff="SELECT username FROM user WHERE username='$session'";
$stuff=mysql_fetch_array($stuff);
$user=$stuff[username];
if(isset($_POST[submit])){
//You need to sanitize user input like this
$msg=mysql_real_escape_string($_POST[msg]);
$name=$user;
$sql=mysql_query("INSERT INTO status(Msg, username)VALUES($msg, $name)");
}
$sql2="SELECT * FROM status";
$res=mysql_query($sql2);
while($row=mysql_fetch_array($res))
{
$username=$row[username]
//You only need to use 1 echo statement here, 3 is unneeded
echo "
$name
</br>
$row[Msg]
";
}
?>
That should work, though I probably made a syntax error somewhere. I tried to keep queries and stuff as simple as possible, such as the query to gather user information.
It's my job to help the next generation, and set a good example for them. And for that I'll gladly lay down my life.