Ken (kk******@wi.rr.com) wrote:
: This does not work because of the need for 's.
: Is there a way to insert a $_SESSION['id'] variable into a database?
There are many ways.
: mysql_query("INSERT INTO master (id) Values('$_SESSION['id']' ) " ) ;
(untested code below)
The simplist change I can think of is something like the following
$session_id = $_SESSION['id'];
mysql_query("INSERT INTO master (id) Values( '$session_id' ) " ) ;
You should also read up on bind variables, which might be even simpler but
I haven't used them enough in php to write an example off the top of my
head.
"Malcolm Dew-Jones" <yf***@vtn1.victoria.tc.ca> wrote in message
news:42******@news.victoria.tc.ca...
Ken (kk******@wi.rr.com) wrote: : This does not work because of the need for 's.
: Is there a way to insert a $_SESSION['id'] variable into a database?
There are many ways.
: mysql_query("INSERT INTO master (id) Values('$_SESSION['id']' ) " ) ;
(untested code below)
The simplest change I can think of is something like the following
$session_id = $_SESSION['id']; mysql_query("INSERT INTO master (id) Values( '$session_id' ) " ) ;
You should also read up on bind variables, which might be even simpler but I haven't used them enough in php to write an example off the top of my head.
I have 70 variables to insert into the database; all SESSION variables. I
would rather stay with the session variables if possible.
Is there a way to use the $_SESSION variable syntax?
What are bind variables. They are not mentioned in my PHP book.
Ken
Sessions aren't special variables, $_SESSION is just an array like any
other. There are several syntaxes for using arrays within strings
(something you're trying to do above) for example:
$str = "I am a string with an {$array['inside']} of me";
$str = "I am also a string with an $array[inside] of me";
$str = "I am another example with an " . $array['inside'] . " of me";
Alternatively I think you can use the php sprintf command:
mysql_query("INSERT INTO master (id) Values('" . sprintf("%s",
$_SESSION['id']) . "' ) " ) ;
-----Original Message-----
From: Ken [mailto:kk******@wi.rr.com]
Posted At: Tuesday, 26 April 2005 6:36 AM
Posted To: comp.lang.php
Conversation: Sessions and mySql
Subject: Sessions and mySql
This does not work because of the need for 's.
Is there a way to insert a $_SESSION['id'] variable into a database?
Thanks.
mysql_query("INSERT INTO master (id) Values('$_SESSION['id']' ) " ) ;
Ken (kk******@wi.rr.com) wrote:
: "Malcolm Dew-Jones" <yf***@vtn1.victoria.tc.ca> wrote in message
: news:42******@news.victoria.tc.ca...
: > Ken (kk******@wi.rr.com) wrote:
: > : This does not work because of the need for 's.
: >
: > : Is there a way to insert a $_SESSION['id'] variable into a database?
: >
: > There are many ways.
: >
: > : mysql_query("INSERT INTO master (id) Values('$_SESSION['id']' ) " ) ;
: >
: > (untested code below)
: >
: > The simplest change I can think of is something like the following
: >
: > $session_id = $_SESSION['id'];
: > mysql_query("INSERT INTO master (id) Values( '$session_id' ) " ) ;
: >
: >
: > You should also read up on bind variables, which might be even simpler but
: > I haven't used them enough in php to write an example off the top of my
: > head.
: I have 70 variables to insert into the database; all SESSION variables. I
: would rather stay with the session variables if possible.
: Is there a way to use the $_SESSION variable syntax?
: What are bind variables. They are not mentioned in my PHP book.
Another easy to describe solution might be to use a variable for the quote
character
$quote="'";
"INSERT INTO master (id) Values( $quote$_SESSION['id']$quote)"
You might need to write that as ${quote}
"INSERT INTO master (id) Values( ${quote}$_SESSION['id']${quote})"
Others have given other example techniques.
Bind variables, google can describe them I'm sure.
You write sql that looks sort of like this
"INSERT INTO master (id) Values(?)"
The ? is where the bind variable is happening. You assign a value for the
bind variable by using a seperate function call. Using them may look more
complicated at first but they are often simpler in the long run. I can't
write php for this sort of stuff without looking it up in the manual, so I
won't give examples.
There is no need for $quote, that's a little crazy :) The problem is
that the following will give a fatal parse error:
$string = "I am $wrong['so'] so do not do this";
It's only wrong because the ' is used for the array key. See my earlier
examples for how to properly do that. Regarding this $quote thing, one
can do the following:
$string = "This isn't a problem at all";
$string = 'This is "not" a problem either';
$string = "This is \"another\" way to do it";
$string = 'And \'this\' is yet another';
Note the mixture of ' and ", this is important. The PHP manual is very
clear on all of this.
I have 70 variables to insert into the database; all SESSION variables. I would rather stay with the session variables if possible.
Is there a way to use the $_SESSION variable syntax?
I can think of two ways to try to solve this:
1) implode/explode functions
2) A bit of fiddling with DB_DataObject from PEAR might help.
Alternatively, move the whole thing under HTTP_Session or HTTP_Session2,
although then one has to deal with beta code
Hi Everyone,
I'll just start, and say I am not a PHP developer (I'm a sysadmin, who
has gotten lumped with a non-working website). But since I like to do
this type of stuff, I though I might...
Hello.
I want to get this blasted .htaccess file sorted out, so I can have
sessions without register_globals being on.
I have looked everywhere for info on this and I mean everywhere...
Hi folks,
I've got a question about sessions in PHP. I'm a *gulp* ASP coder, so
please bear with me.
I developed a PHP site a few months back that has a password protected
entry into a...
Hi Gurus
I am basically sorry that I have to bother you about this. I am a PHP
beginner and I have been studying sessions and cookies over the last few
weeks. I have learned lots, but I am...
Hello there - we have a fairly busy server and we just started to have
problems with PHP sessions failing. We've never had this problem before and
to be honist, out server traffic is lower than it...
Hi All
Seem to be getting zombie sessions. /tmp/sess_ exist and are owned by daemon. I am guessing and
these could come from brower crashes, networks gone down ... etc ...
even from stuff that...
I have been "Googling" for about an hour and am turning up squat! I just
started receiving this error when trying to log into a MS Access database
from a vb .net web application. Recycling IIS...
Hello
Some data are common to all user sessions, and to improve
performance/save resources, I'd like to share those data between all
sessions, so that each user doesn't have to hit MySQL for the...
Hi.
Problem is that all sessions are removed when I am using this code...
By this code I am deleting files in a particular folder and then that folder..
Need help......
code is:
try
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...