php - update the session field in database -
i have database. had created a table containing 1 row in db if wasn't constructed before.
why has 1 row use keep info.
there field of type nvarchar(100)
want use store session id, , here comes headache me:
it seems can't insert(i use phpmyadmin
check , it's blank) , update(syntax error...) session id obtained session_id()
, returned string
.
here portion of code relating action:
//uamip,uamport in url;i use $_get[] $_session[uamport] = $_get['uamport']; $_session[uamip] = $_get['uamip']; **$_session[sid] = session_id();** //construct $sql="create table trans_vector( `index` int not null auto_increment, `sid` nvarchar(100), `uamip` char(15), `uamport` int, primary key (`index`) )" ; mysql_query($sql); //insert(first time, not constructed) $sql="insert trans_vector (sid,uamip,uamport) values( '$_session[sid]', '$_session[myuamip]', '$_session[myuamport]' )"; mysql_query($sql); //update(from 2nd time , later, table exists, want update sid part) $sql="update trans_vector set sid="**.**$_session[sid]; mysql_query($sql)
now, when use phpmyadmin check sid field
after insert
or update
, it blank;
but if this:
$vector=mysql_fetch_array(mysql_query("select tables 'trans_vector'"));
and echo $vector[sid]
,then it's printed on webpage.
another question is:
with update
statement above, such error:
"unknown column xxxxxx....(some session id returned, seems translate first , put in sql statement, ** treating column name** that's not want!)"
i tried type in create statement, , lots of syntax of update statement(everything!!!) give error.
i dealing trouble '
, string representation containing variable latter's value want... , maybe problem arise type in create , string representation in update
statement?
should cast()
statement helpful me?
wish can me deal this...and list real reference of such issue in php
?
thanks much!!
$insert = "insert trans_vector (`sid`, `uamip`, `uamport`) values( '".$_session["sid"]."', '".$_session["myuamip"]."', '".$_session["myuamport"]."' )";
this should solve @ least warnings, if not errors.
and update...
$update = "update trans_vector set `sid`='".$_session["sid"]."';";
notes code: array values have put string operator '.' , cannot inserted directly. array indexes must strings (note ") or integers.
column names should have `` around them. insert string sql, have put string ''s, parser knows string , column name. without ''s parser assuming stating column.
and mysql_escape_string, assumed handle before storing data sessions. without those, might can unwanted sql injections. , in case did not that, can either (before create queries):
foreach($_session $key => $value) $_session[$key] = mysql_escape_string($value);
or manually escape strings when create query.
Comments
Post a Comment