luminous Posted December 15, 2009 Share Posted December 15, 2009 I'm passing some values into a function in the form of an array. The values pass into the function fine (i've checked this with a print_r inside the function, the values are set so I know they're being passed into the function) however when I move these values into the query they don't seem to show up // function..... $params is array being passed in function new_exhibition($params) { /// database connection... db_connect(); // print_r on $params, the array is full of values set outside the function.... print_r($params); // the query... $query = sprintf("INSERT INTO exhibitions SET exhibitioname = '%s', startdate = '%s', enddate = '%s', Year = '%s', details = '%s', address= '%s' ", mysql_real_escape_string($params['exhibitioname']), mysql_real_escape_string($params['startdate']), mysql_real_escape_string($params['enddate']), mysql_real_escape_string($params['Year']), mysql_real_escape_string($params['details']), mysql_real_escape_string($params['address'])); Each time I get back "Undefined index" error for the escaped values. I've tried printing the query string and it's empty each time so I'm at a loss to know what's going on here. Please help! Quote Link to comment https://forums.phpfreaks.com/topic/185275-undefined-index-mysql_real_escape_string-problem/ Share on other sites More sharing options...
sasa Posted December 15, 2009 Share Posted December 15, 2009 can you post output of print_r Quote Link to comment https://forums.phpfreaks.com/topic/185275-undefined-index-mysql_real_escape_string-problem/#findComment-978032 Share on other sites More sharing options...
mrMarcus Posted December 15, 2009 Share Posted December 15, 2009 is your array in fact an 'associative' array? pate the results of the print_r() here if you're unsure what that is. Quote Link to comment https://forums.phpfreaks.com/topic/185275-undefined-index-mysql_real_escape_string-problem/#findComment-978033 Share on other sites More sharing options...
luminous Posted December 15, 2009 Author Share Posted December 15, 2009 Here you go: Array ( [post] => Array ( [exhibitioname] => Test [startdate] => 2009-11-09 [enddate] => 2009-11-09 [Year] => 2009 [address] => Adress Test [details] => This is a test ) ) Quote Link to comment https://forums.phpfreaks.com/topic/185275-undefined-index-mysql_real_escape_string-problem/#findComment-978034 Share on other sites More sharing options...
sasa Posted December 15, 2009 Share Posted December 15, 2009 you need key 'post' in your array ... mysql_real_escape_string($params['post']['exhibitioname']), mysql_real_escape_string($params['post']['startdate']), mysql_real_escape_string($params['post']['enddate']), mysql_real_escape_string($params['post']['Year']), mysql_real_escape_string($params['post']['details']), mysql_real_escape_string($params['post']['address'])); Quote Link to comment https://forums.phpfreaks.com/topic/185275-undefined-index-mysql_real_escape_string-problem/#findComment-978038 Share on other sites More sharing options...
luminous Posted December 15, 2009 Author Share Posted December 15, 2009 ahhh my saviour! I don't know how I didn't see that it's been a long day! Many thanks! Quote Link to comment https://forums.phpfreaks.com/topic/185275-undefined-index-mysql_real_escape_string-problem/#findComment-978044 Share on other sites More sharing options...
sasa Posted December 15, 2009 Share Posted December 15, 2009 mark topic solved Quote Link to comment https://forums.phpfreaks.com/topic/185275-undefined-index-mysql_real_escape_string-problem/#findComment-978049 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.