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
https://forums.phpfreaks.com/topic/153582-solved-problem-with-variables/
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();

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')";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.