Jump to content

[SOLVED] problem with variables


justAnoob

Recommended Posts

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

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.