EchoFool Posted February 2, 2009 Share Posted February 2, 2009 I have a form which I am trying to place the ItemID in the submit button like so: <input type="submit" name="Bin[<?php echo $ItemID;?>]" value="Throw Away"> And then in my PHP process I have : <?php $ID = strtolower(mysql_real_escape_string(stripslashes($_POST['Bin']))); ?> But I get an error saying this: Notice: Array to string conversion in test.php on line 1509 I've done this kind of thing with checkboxes... surely it should work with submit buttons too ? What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
Snart Posted February 2, 2009 Share Posted February 2, 2009 $_POST['Bin'] is an array with one element in it (the ItemID). The functions you are using strtolower(mysql_real_escape_string(stripslashes())) are string functions and will not work on an array. Quote Link to comment Share on other sites More sharing options...
aebstract Posted February 2, 2009 Share Posted February 2, 2009 $_POST['Bin'] doesn't exist since you are adding a variable on to it, it should be Bin$ItemID. I just did something almost exactly the same. With mine I ended up doing something like this: $postname = image.$id; $_POST[$postname] Quote Link to comment Share on other sites More sharing options...
EchoFool Posted February 2, 2009 Author Share Posted February 2, 2009 $_POST['Bin'] doesn't exist since you are adding a variable on to it, it should be Bin$ItemID. I just did something almost exactly the same. With mine I ended up doing something like this: $postname = image.$id; $_POST[$postname] Yeh but then I would have a variable carrying the string "Bin23" wouldn't I? Assuming the ID is 23... so how would I get it to just say 23 so I can check my table of items for the ID ? =/ Quote Link to comment Share on other sites More sharing options...
aebstract Posted February 2, 2009 Share Posted February 2, 2009 You're making your submit button's name Bin32, so in order to get the value you need to use Bin32. Might be needing some more code to help you and what exactly you're trying to do? Quote Link to comment Share on other sites More sharing options...
Snart Posted February 2, 2009 Share Posted February 2, 2009 How about adding a hidden input field and leaving the submit button just for what it's made for: submitting the form? Quote Link to comment Share on other sites More sharing options...
EchoFool Posted February 2, 2009 Author Share Posted February 2, 2009 Well im trying to make an array..so that when the submit button is pressed it will know what ItemID it needs to update. So my form is like this: <form> <?php While($row2 = mysql_fetch_assoc($Get)){ $ItemID = $row2['ItemID']; $Quantity = $row2['Quantity']; ?> <input type="text" size="16" name="Throw" value=""><br> <input type="submit" name="Bin[<?=$ItemID?>]" value="Throw Away"> <?php } ?> </form> So say I hit one of the submit buttons which is Bin[32] ... i thought that would make Bin an array like it would on checkboxes..so that I could grab the ID 32 in processing form? Quote Link to comment Share on other sites More sharing options...
aebstract Posted February 2, 2009 Share Posted February 2, 2009 well in that code your form doesn't have an action or method or anything. This is why it is good to have actual code presented, and if this is.. then there is problem 1. Also, if you're gonna have a submit button for each bin item, each bin item is also going to have to have its own form, so the actual form will have to be included in to the loop. If this is true, each form will need it's own name, I would suggest using your id to uniquely name each form. Quote Link to comment Share on other sites More sharing options...
gevans Posted February 2, 2009 Share Posted February 2, 2009 I have a form which I am trying to place the ItemID in the submit button like so: <input type="submit" name="Bin[<?php echo $ItemID;?>]" value="Throw Away"> And then in my PHP process I have : <?php $ID = strtolower(mysql_real_escape_string(stripslashes($_POST['Bin']))); ?> But I get an error saying this: Notice: Array to string conversion in test.php on line 1509 I've done this kind of thing with checkboxes... surely it should work with submit buttons too ? What am I doing wrong? Just use a hidden field for the ID <input type="hidden" name="ID" value="<?php echo $ItemID;?>" /> Quote Link to comment Share on other sites More sharing options...
sasa Posted February 2, 2009 Share Posted February 2, 2009 for your 1st code try <?php $_POST['Bin'][23]='Throw Away';//posted by form $ids = array_keys($_POST['Bin']); echo $id = strtolower(mysql_real_escape_string(stripslashes($ids[0]))); ?> Quote Link to comment Share on other sites More sharing options...
EchoFool Posted February 2, 2009 Author Share Posted February 2, 2009 for your 1st code try <?php $_POST['Bin'][23]='Throw Away';//posted by form $ids = array_keys($_POST['Bin']); echo $id = strtolower(mysql_real_escape_string(stripslashes($ids[0]))); ?> Thank you works a treat! Quote Link to comment 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.