cobusbo Posted August 31, 2014 Share Posted August 31, 2014 Hi Im having some trouble implementing info into a database I got the line $mxitid = $_SERVER["HTTP_X_MXIT_USERID_R"]; Which I'm importing to my database via $sql = "INSERT INTO ".$dbTable." (StringyChat_ip,StringyChat_name,StringyChat_message,StringyChat_time,mxit_id) VALUES (\"$ip\",\"$name\",\"$message\",$post_time,$mxitid)"; $result = mysql_query($sql); well its working perfectly, but the problem I'm experiencing is that if my value $_SERVER["HTTP_X_MXIT_USERID_R"] cannot be retrieved I can't insert any info to my database. the $_SERVER["HTTP_X_MXIT_USERID_R"] is being used via a specific platform called mxit, so if I use any other platform it don't work. Is there maybe a way to change the line $mxitid = $_SERVER["HTTP_X_MXIT_USERID_R"]; to a function if the info couldn't be retrieved to insert another default value like "ADMIN" rather in the place of it? Quote Link to comment https://forums.phpfreaks.com/topic/290767-adding-info-to-mysql-database/ Share on other sites More sharing options...
Solution lawless Posted August 31, 2014 Solution Share Posted August 31, 2014 A simple checkup before you go for the query should work this out. Just check if the value has been stored into the variable, else put some default value there. $mxitid = $_SERVER["HTTP_X_MXIT_USERID_R"]; if(!isset($mxitid)) { $mxitid = "DEFAULT"; } Quote Link to comment https://forums.phpfreaks.com/topic/290767-adding-info-to-mysql-database/#findComment-1489476 Share on other sites More sharing options...
cobusbo Posted August 31, 2014 Author Share Posted August 31, 2014 A simple checkup before you go for the query should work this out. Just check if the value has been stored into the variable, else put some default value there. $mxitid = $_SERVER["HTTP_X_MXIT_USERID_R"]; if(!isset($mxitid)) { $mxitid = "DEFAULT"; } Thank you Quote Link to comment https://forums.phpfreaks.com/topic/290767-adding-info-to-mysql-database/#findComment-1489479 Share on other sites More sharing options...
CroNiX Posted August 31, 2014 Share Posted August 31, 2014 You need to check if it is isset() BEFORE you try assigning it to a variable. Quote Link to comment https://forums.phpfreaks.com/topic/290767-adding-info-to-mysql-database/#findComment-1489498 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.