brem13 Posted March 20, 2010 Share Posted March 20, 2010 hey, im trying to take a filename from an array and put it into a mysql database, but its not storing it any help? mysql_query("UPDATE $table SET mainPic = '$file_name[$i]' WHERE email = '$email'"); Quote Link to comment https://forums.phpfreaks.com/topic/195935-putting-array-values-in-mysql-database-trouble/ Share on other sites More sharing options...
brem13 Posted March 20, 2010 Author Share Posted March 20, 2010 the array is stored in $file_name[$i] and it just posts a blank to the field in the database, but if i remove the [$i] it will post 'Array' into the field Quote Link to comment https://forums.phpfreaks.com/topic/195935-putting-array-values-in-mysql-database-trouble/#findComment-1029212 Share on other sites More sharing options...
skurai Posted March 20, 2010 Share Posted March 20, 2010 how are you storing the files into the array? can you post more code? Quote Link to comment https://forums.phpfreaks.com/topic/195935-putting-array-values-in-mysql-database-trouble/#findComment-1029219 Share on other sites More sharing options...
DavidAM Posted March 20, 2010 Share Posted March 20, 2010 I think there are two things you need to do here. 1) since the variable inside the literal string is an array, mark it with cury braces; mysql_query("UPDATE $table SET mainPic = '{$file_name[$i]}' WHERE email = '$email'"); 2) you definitely need to escape the value - to do this we have to pull it out of the literal (so #1 no longer applies) - unless you escaped it when you put it in the array. $file = mysql_real_escape_string($file_name[$i]); mysql_query("UPDATE $table SET mainPic = '$file' WHERE email = '$email'"); you need to escape the $email address as well if haven't already. Quote Link to comment https://forums.phpfreaks.com/topic/195935-putting-array-values-in-mysql-database-trouble/#findComment-1029231 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.