Jump to content

[SOLVED] Help with value in a POST button


EchoFool

Recommended Posts

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?

Link to comment
Share on other sites

$_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  ? =/

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;?>" />

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.