DamienRoche Posted February 21, 2009 Share Posted February 21, 2009 I'm having trouble inserting constant into database. Here are the relevant lines: define("IP", clean($_SERVER['REMOTE_ADDR'])); mysql_query("INSERT INTO sessions (user,ip,sid) VALUES ('$user','IP','$sid')") or die(mysql_error()); Obviously, it is insert 'IP' into database and not the constant value. Is there a way around this.... on a more important note - with the use being evident - am I going about this the wrong way? Thanks. Link to comment https://forums.phpfreaks.com/topic/146242-can-you-insert-defined-constant-into-database/ Share on other sites More sharing options...
Cal Posted February 21, 2009 Share Posted February 21, 2009 try this: mysql_query("INSERT INTO sessions (user,ip,sid) VALUES ('$user','" . IP . "','$sid')") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/146242-can-you-insert-defined-constant-into-database/#findComment-767758 Share on other sites More sharing options...
wildteen88 Posted February 21, 2009 Share Posted February 21, 2009 PHP does not parse constants within strings, you'll have to concatenate it mysql_query("INSERT INTO sessions (user,ip,sid) VALUES ('$user','".IP."','$sid')") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/146242-can-you-insert-defined-constant-into-database/#findComment-767759 Share on other sites More sharing options...
DamienRoche Posted February 21, 2009 Author Share Posted February 21, 2009 PHP does not parse constants within strings, you'll have to concatenate it mysql_query("INSERT INTO sessions (user,ip,sid) VALUES ('$user','".IP."','$sid')") or die(mysql_error()); I thought that was concatenating it. Could you elaborate? Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/146242-can-you-insert-defined-constant-into-database/#findComment-767762 Share on other sites More sharing options...
Cal Posted February 21, 2009 Share Posted February 21, 2009 Yes what he wrote was the concenated version. Link to comment https://forums.phpfreaks.com/topic/146242-can-you-insert-defined-constant-into-database/#findComment-767763 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.