justAnoob Posted April 11, 2009 Share Posted April 11, 2009 i need to get the username of the user that is signed in to send it to 2 different rows in mysql. one of my variables is $findit = $_SESSION['id']..... i need to use that session id for another variable for another row in the database... and yes,,, i need to have the name in two spots in the database(same table) what can i do to get the username again Quote Link to comment Share on other sites More sharing options...
xtopolis Posted April 11, 2009 Share Posted April 11, 2009 Cool. What's your question? Where's your code? Quote Link to comment Share on other sites More sharing options...
xtopolis Posted April 11, 2009 Share Posted April 11, 2009 Make a copy of $_SESSION['id'] ?? You already have the name once. Reuse the same variable or make a copy of it and use it again... is there something more your having trouble with? Quote Link to comment Share on other sites More sharing options...
justAnoob Posted April 11, 2009 Author Share Posted April 11, 2009 <?php session_start(); include "connection.php"; mysql_connect("$host", "$username", "$password") or die("Could not connect."); mysql_select_db("$db_name") or die("Could not find database"); $sendto = mysql_real_escape_string($_POST['sendto']); $subject = mysql_real_escape_string($_POST['subject']); $message = mysql_real_escape_string($_POST['message']); $findit = $_SESSION['id']; $from = this needs to be $_SESSION['id'] also,, but it wont let me,, just get an error //read this line $result=mysql_query("SELECT id FROM members WHERE username = '$findit'"); $row=mysql_fetch_assoc($result); $user_id = $row['id']; $sql = "INSERT INTO member_messages(user_id, sendto, subject, message, from)VALUES('$findit', '$sendto','$subject','$message', '$from')"; mysql_query($sql) or die('There was an error.'); mysql_close(); Quote Link to comment Share on other sites More sharing options...
justAnoob Posted April 11, 2009 Author Share Posted April 11, 2009 what do you mean make a copy ..... this is from the login that defines the session variable <?php $_SESSION['id1'] = "$username"; //something like this,, tried it,, doesn't work $_SESSION['id'] = "$username"; ?> Quote Link to comment Share on other sites More sharing options...
xtopolis Posted April 11, 2009 Share Posted April 11, 2009 From your code it looks like you could change either: $findit = $_SESSION['id']; $from = $_SESSION['id']; or $sql = "INSERT INTO member_messages(user_id, sendto, subject, message, from)VALUES('$findit', '$sendto','$subject','$message', '$findit')"; Quote Link to comment Share on other sites More sharing options...
justAnoob Posted April 11, 2009 Author Share Posted April 11, 2009 Will try a few things,, will call this solved til later. Quote Link to comment 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.