Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possessing radio buttons ??

Status
Not open for further replies.

NevadaJones

Programmer
Sep 5, 2006
26


I have removed extra code from the input form I posted here. There are three sets of radio buttons each set has the unique name as shown. Because the input buttons I posted are checked they have the indicated value. This information is submitted to the process form by the submit button.
Code:
<form id='Update' name='Update' action='process.php' method='POST'>

<input type='radio' name='id[9]' value'1'checked> 1

<input type='radio' name='id[10]' value'1'checked> 1

<input type='radio' name='id[11]' value'3'checked> 3

<input type='submit' name='admin' value='Up Date Status'>
</form>
NOW how do I get the process form to handle what is submitted? With the code I have I can print each radio button name. What do I have to do to display and INPUT into a database that the radio name 9 has a value of 1 and so forth. Thanks for any more code you can give.

Code:
foreach ($_POST['id'] as $id=>$value){
echo $_POST['id'] . "&nbsp; &nbsp;" . $id . "<p>";
}

 
it depends on what you need to do? do you need to edit a value in the database or insert a new row? If you need to insert a new row you would do something like:

foreach ($_POST['id'] as $id=>$value){
echo $_POST['id'] . "&nbsp; &nbsp;" . $id . "<p>";

//query should be inside foreach loop
mysql_query("insert into table (id9,id10,id11) values ($_POST[id9],$_POST[id10],$_POST[id11])");

}

I am guessing that this is what you need because you have multiple id[9] values, etc...
 

Thank you kaptlid. I had a major problem in my radio button input lines by leaving out the = for values'1', etc.

Now the values are being properly passed and I can tell by the echo statement I included for testing. I need to improve my query statement because it is not UPDATEing the table completely.

Code:
$array = $_POST['id'];
foreach($array as $key => $value)
{
echo $key.' is: '.$value . '<br>';

	$SendQuery = "UPDATE $TableName 
		SET status = '$value'
		WHERE id = '$key'";
}
 
if you are inputting numbers into an INT field type make sure NOT to have the single quotes.

Why do you have a dollar sign before TableName?

mysql_query("update tablename set status = '$value' where id = $key");
 
A value is assign to $TableName outside of the query. My script is working now. This link.

I had not included my mysqli_query() statement inside the brackets with the for loop.

Thanks for the replies.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top