Jump to content

Recommended Posts

Hello,

 

I have an issue with posting data using check boxes.

 

I am generating a form from data in an mysql table. I get a list people/data with check boxes so I can select which ones I want to make changes to.

 

Here is the form.

<form action="home.php" method="POST">
<?php
//this subtracts goblin points.
$chid = $_SESSION['chapter_id'];
$query = "SELECT * FROM demographics join id ON (id.id = demographics.id) where id.chid='$chid' ORDER BY demographics.lastname";
$result = mysql_query($query) or die (mysql_error());
echo "<table border='1' cellspacing='15'>";
echo "<tr><td></td><td>Players Name</td><td>Goblin Point Amount</td><td>Reason</td></tr>";
while ($row = mysql_fetch_array($result))
{
extract($row);
$uid = $row[id];
$pname= getplayersname($uid);
echo "<tr><td><input type='checkbox' name='myarray[]' value='$uid' /></td>\n";
echo "<td>$pname</td>\n";
echo "<td><input type='int' name='amt' size='5'></td><td><input type='reason' name='reason' size='20'></td></tr>\n";
}
echo "</table>\n";
?>
<input type="hidden" name="action" value="removegobbies">
<input type="submit" value="Subtract Goblin Points" name="esubmit">
</form>

 

As you can see I have the checkboxes setup as an array and I am using an id as the identifier for what I want to do.

 

now the problem I have is I can't figure out how to have the variables amt and reason post. I know I made a mistake here is the script that is receiving the data from the form.

 

foreach($_POST['myarray'] as $uid) 
{
// $checkbox will have the value assigned to it from uid
$amt = $_POST ['amt'];
$reason = $_POST ['reason'];
$by_id = $_SESSION['user_id'];
$aOr = 'rem';
$date = date("Y-m-d");
$chid = $_SESSION['chapter_id'];
$pname = getplayersname($uid);
$gobbies = getgoblinpoints($uid);
$newgobbietotal = $gobbies-$amt;

echo " ID - $uid, Amount - $amt, Reason - $reason, BY - $by_id, $aOr, Date - $date, Chapter - $chid, Original Gobbies - $gobbies, New Gobbies - $newgobbietotal.<p>";
}

 

I went straight to the foreach loop to open up the array and go through it. It works for the id info but the amt and reason just wont come over. now I think its a simple issue of setting up all the data to transfer over as the array but I can't figure out how to do it.

 

any suggestion on how I can correct the code would be appreciated.  I'm not really good with arrays but if that's the best way to correct this, please point me to a tutorial or explain a bit about how it works.

 

Thanks 

 

 

$amt = $_POST['amt'];
$reason = $_POST['reason'];

 

Remove the spaces between $_POST and [. I do not think that is kosher (but not 100% sure)

 

I would brush up on your html for forms:

 

<input type='int' name='amt' size='5'></td><td><input type='reason' name='reason' size='20'>

 

That should be:

<input type='text' name='amt' size='5'></td><td><input type='text' name='reason' size='20'>

 

There is no such type as int or reason for forms in HTML.

thanks for the suggestion.

 

the issue is the script works if I pull the check box option out and set it up to update 1 file at a time. I am trying to figure out how to convert this all to work with the check boxes so i can get a list that the users can select multiple files to update.

 

I think it is an array issue just trying to figure out how to do the array...

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.