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 Link to comment https://forums.phpfreaks.com/topic/153582-solved-problem-with-variables/ 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? Link to comment https://forums.phpfreaks.com/topic/153582-solved-problem-with-variables/#findComment-807022 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? Link to comment https://forums.phpfreaks.com/topic/153582-solved-problem-with-variables/#findComment-807027 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(); Link to comment https://forums.phpfreaks.com/topic/153582-solved-problem-with-variables/#findComment-807028 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"; ?> Link to comment https://forums.phpfreaks.com/topic/153582-solved-problem-with-variables/#findComment-807032 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')"; Link to comment https://forums.phpfreaks.com/topic/153582-solved-problem-with-variables/#findComment-807034 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. Link to comment https://forums.phpfreaks.com/topic/153582-solved-problem-with-variables/#findComment-807036 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.