flambo Posted February 27, 2012 Share Posted February 27, 2012 Hi, Apologies if this is rather easy but wondered how you would get around the following problem. I have a post being sent on a checked form that has the name set to a value used in my DB, for example: <input type="checkbox" name="<?PHP echo $rows ["catID"] ?>"> Where name would equal something like 11. I'm trying to right some code that inserts data from the rows that have been checked, bit like the below: while($rows = $database->fetch_array($result)){ $strSQL='INSERT INTO affiliate_join_cat (ajcCatID, ajcAffID) VALUES ('.$rows["catID"].', '.$_POST["affID"].')'; if ($_POST($rows["catID"])=="on"){ $database->query($strSQL); so my post will look something like 11 = on, dependent on the row checked. But there is something wrong with this part of the code: $_POST($rows["catID"])=="on" my thoughts are that until catID actually equals 11 this does not evaluate to anything? So have tried using empty and isset to handle it without any success. Not sure what to do next? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/257866-post-value-not-evaluating-true/ Share on other sites More sharing options...
AyKay47 Posted February 27, 2012 Share Posted February 27, 2012 if($_POST[$rows["catID"]] == "on"); //square brackets Quote Link to comment https://forums.phpfreaks.com/topic/257866-post-value-not-evaluating-true/#findComment-1321661 Share on other sites More sharing options...
ManiacDan Posted February 27, 2012 Share Posted February 27, 2012 AK's code is correct. You had parens instead of brackets, which would cause PHP to attempt to execute a function named after the $_POST array, but that would throw a fatal error. You're going about this wrong btw. Name all your checkboxes "catID[]". All of them, named JUST like that. Each of their VALUES needs to be the actual catID. Then, in your code, $_POST['catID'] will be an array of all the checked catIDs. Quote Link to comment https://forums.phpfreaks.com/topic/257866-post-value-not-evaluating-true/#findComment-1321665 Share on other sites More sharing options...
flambo Posted February 27, 2012 Author Share Posted February 27, 2012 Thank you very much for both bits of advise, it helped greatly. Quote Link to comment https://forums.phpfreaks.com/topic/257866-post-value-not-evaluating-true/#findComment-1321788 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.