php - session is not saved for some variables -
i have 2 pages in website; 1 gets username
url, puts $_session
, displays list of groups user belongs to.
when user chooses group, site goes next page (the group.php
page) , gives grouping name in url used in grouping page.
in grouping page there form send messages displayed in grouping page (kindda facebook wall, guess).
here's problem: in grouping list page username
sent session; after grouping name picked-up grouping page sent session well, reason when page gets if(isset($_post['texts']))
part- remembers username not groupname.
any thought why that? next code grouping page.
<?php session_start(); include_once("../connect.php"); $username = $_session['username']; $result = mysqli_query($conn, "select id users username='$username'"); while($row = mysqli_fetch_array($result)) { $uid = $row['id']; } if(isset($_get['groupname'])) { $groupname = $_get['groupname']; } $result = mysqli_query($conn, "select id groups groupname='$groupname'"); while($row = mysqli_fetch_array($result)) { $gid = $row['id']; } $_session['groupname'] = $groupname; ?> <!doctype html> <html> <head> <meta charset="utf-8"> </head> <body> <form action= <?php echo "'group.php?id=" . $gid . "'"; ?> method="post" name="newtext"> <textarea name="texts" rows="4" cols="30"></textarea> <input type="submit" id="subtext" name="submit" value="submit" /> </form> <?php //add text message if(isset($_post['texts'])){ $texts = $_post['texts']; if($texts == "") { echo "<script>alert('no message writen')</script>"; }else{ mysqli_query($conn, "insert texts (`sender`, `sent`, `group`, `text`) values ('$uid', now(), '$gid', '$texts');"); echo "<script>alert('message recieved!')</script>"; } } ?> </div> </body> </html>
it because in case $_get['groupname'] not exist more.
echo "'group.php?id=" . $gid . "'";
i dont see using $_get['id'] place, action should
group.php?groupname=groupname_here instead of group.php?id=1
this should work:
<form action="group.php?groupname=<?php echo $groupname; ?>" method="post" name="newtext">
i add together else statement here decide if variable not exist.
if(isset($_get['groupname'])) { $groupname = $_get['groupname']; }
php mysql session mysqli
No comments:
Post a Comment