Jump to content

Session info into database


davidcriniti

Recommended Posts

Hi,

 

I'm working with sessions for the first time and have been able to put a member's id into the database. However, when I try and put their display name into the database I got a message saying

 

Unknown column 'xyz' in 'field list'

 

xyz was the display name for the session. Just can't seem to see what I'm doing wrong.

 

In the code below, I even tried changing $_SESSION['member_display_name'] to $_SESSION['member_id'], in which case the correct id was inserted into both the member_id and the member_display_name fields in the database, so I know the table is set up correctly.

 

Any tips?

 

 

 

//**********************SEND TO DATABASE****************************

include 'mysql_connect.php'; 

  $query = "INSERT INTO uploads (date, member_id, upload_name, upload_title, upload_type, subject, topic, year, status, keywords, description, member_display_name, firstname,  lastname)" . "VALUES (NOW(), ".$_SESSION['member_id'] . ",'$upload_nameX', '$upload_title', '".$EXPLODED_STRING[1]."', '$subject', '$topic', '$year',  '$status', '$keywords', '$description',  ".$_SESSION['member_display_name'] . ", '$firstname', '$lastname')";
//if($query){echo 'data has been placed'}
mysql_query($query) or die(mysql_error());
$upload_id = mysql_insert_id();

//***********************END OF DATABASE CODE***********************

Link to comment
Share on other sites

I thought I did surround it with quotes. Did I do so incorrectly? ...here's the relevant bit of code, with the preceding and following fields. I tried a few variations of quote placements after your comment, but to no avail I'm afraid.

 


'$description',  ".$_SESSION['member_display_name'] . ", '$firstname', 

Link to comment
Share on other sites

That isn't enclosed in quotes. The double quote ends the quoted string, then the full stop concatenates the array element to the string, then the next full stop concatenates the following quoted string.

 

$_SESSION['member_display_name'] = 'string';
$query = "VALUES ( '$description',  ".$_SESSION['member_display_name'] . ", '$firstname')";
// ABOVE WOULD BE THE SAME AS BELOW
$query = "VALUES ( '$description', string, '$firstname')";

 

That can be made less confusing and easier to read by simply enclosing any associative array elements in curly braces.

$query = "VALUES ( '$description',  '{$_SESSION['member_display_name']}', '$firstname')";

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.