biff423 Posted September 23, 2009 Share Posted September 23, 2009 Info collected from form using hidden fields with values of 1 for 'yes' and 0 for 'no': $angus=$_POST['angus']; $brangus=$_POST['brangus']; $charolais=$_POST['charolais']; $data="$angus$brangus$charolais"; so $data should equal 100 include("addtolistx2.php"); _____________________________________ Code in include addtolistx2.php: list($angus,$brangus,$charolais) = $data $sql = mysql_query("INSERT INTO list (angus,brangus,charolais) VALUES ('$angus','$brangus','$charolais')") or die (mysql_error()); so $angus should be 1, $brangus should be 0 and $charolais should be 0 - and those values should be entered into the proper columns in database BUT - the values are not showing up in the database. Please help - I believe the problem is with unpacking the list and assigning variables but I am not sure how to correct. Thank you Marci - please be kind - sorta a newbie Link to comment https://forums.phpfreaks.com/topic/175223-assign-variables-list-help/ Share on other sites More sharing options...
MatthewJ Posted September 23, 2009 Share Posted September 23, 2009 Why are you comibing them just to split them up? They are already in separate vars... Link to comment https://forums.phpfreaks.com/topic/175223-assign-variables-list-help/#findComment-923527 Share on other sites More sharing options...
Mark Baker Posted September 23, 2009 Share Posted September 23, 2009 There is no need to "pack" and "unpack" your variables when using an include.... especially when you're unpacking them incorrectly $data is being defined as a string, so you'd need to convert it to an array before using list. list($angus,$brangus,$charolais) = str_split($data); Link to comment https://forums.phpfreaks.com/topic/175223-assign-variables-list-help/#findComment-923528 Share on other sites More sharing options...
Bricktop Posted September 23, 2009 Share Posted September 23, 2009 Hi biff423, Also, as you are entering POSTed data directly into a MySQL query you need to do some validation/sanitisation to avoid possible MySQL Injection attacks. Very basic protection would be to use mysql_real_escape_string(), i.e.: $angus=mysql_real_escape_string($_POST['angus']); $brangus=mysql_real_escape_string($_POST['brangus']); $charolais=mysql_real_escape_string($_POST['charolais']); Make sure you have a database connection before doing this otherwise it won't work. Have a read of Daniel's excellent PHP security tutorial here for further information http://www.phpfreaks.com/tutorial/php-security Hope this helps. Link to comment https://forums.phpfreaks.com/topic/175223-assign-variables-list-help/#findComment-923532 Share on other sites More sharing options...
biff423 Posted September 23, 2009 Author Share Posted September 23, 2009 Thank you to all - total whoops on my part - I used the code from another form and didn't really think it through - I took out teh $data in the first file and the list () = $data in the second file and it is all working fine! Thanks for your help! Marci Link to comment https://forums.phpfreaks.com/topic/175223-assign-variables-list-help/#findComment-923559 Share on other sites More sharing options...
biff423 Posted September 23, 2009 Author Share Posted September 23, 2009 How do i marked this solved? Link to comment https://forums.phpfreaks.com/topic/175223-assign-variables-list-help/#findComment-923562 Share on other sites More sharing options...
Bricktop Posted September 23, 2009 Share Posted September 23, 2009 Scroll down almost to the bottom of the page and there is a little "Topic Solved" link inside a blue bar, just click that Link to comment https://forums.phpfreaks.com/topic/175223-assign-variables-list-help/#findComment-923563 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.