PHP remeber checked checkboxes - php

I am trying to have a filter using checkboxes. Problem is when I unselect some boxes
and submit values, all boxes are selected again. I think the problem can be here
if (isset($_POST['option_meno']))
What can be the problem?
And yes Im new here, so any ideas hot to make my code simpler would help me also.
Thank you.
<?php
// Make a MySQL Connection
$query_o_meno = "SELECT meno FROM uctovnictvo GROUP BY meno ORDER BY meno";
$result_meno = mysql_query($query_o_meno) or die(mysql_error());
?>
<form method="post">
<?php
if (isset($_POST['Filtrovat'])) {
// Print checked checkboxes
echo "<strong>Meno:</strong>";
echo "<br />";
while($row = mysql_fetch_array($result_meno)){
//I believe the problem is line below -----------------------------
if (isset($_POST['option_meno'])) {
echo "<input type='checkbox' name='option_meno[]' value='".$row['meno']."' checked />" . $row['meno'];
echo "<br />";
//}
}
else{
echo "<input type='checkbox' name='option_meno[]' value='".$row['meno']."' / >" . $row['meno'];
echo "<br />";
}
}
}
else{
$option_meno = array();
echo "<strong>Meno:</strong>";
echo "<br />";
while($row = mysql_fetch_array($result_meno)){
echo "<input type='checkbox' name='option_meno[]' value='".$row['meno']."' checked />" . $row['meno'];
echo "<br />";
$option_meno[] = $row['meno'];
}
}
?>
<input type="submit" name="Filtrovat" value="Filtrovat" />
</form>

This is not tested, but should work:
if (isset($_POST['Filtrovat']))
{
// Print checked checkboxes
echo "<strong>Meno:</strong>";
echo "<br />";
while($row = mysql_fetch_array($result_meno))
{
$checked = "";
if(isset($_POST['option_meno']))
$checked = in_array($row['meno'],$_POST['option_meno'])?"
checked = 'checked' ":"";
echo "<input type='checkbox' name='option_meno[]'
value='".$row['meno']."' $checked / >" . $row['meno'];
echo "<br />";
}
}

Since you're doing name='option_meno[]', $_POST['option_meno'] will be an array. That array will always be set as long as at least one checkbox is checked. Try something like this:
<?php
// Make a MySQL Connection
$query_o_meno = "SELECT meno FROM uctovnictvo GROUP BY meno ORDER BY meno";
$result_meno = mysql_query($query_o_meno) or die(mysql_error());
?>
<form method="post">
<?php
if (isset($_POST['Filtrovat'])) {
// Print checked checkboxes
echo "<strong>Meno:</strong>";
echo "<br />";
while($row = mysql_fetch_array($result_meno)){
//I believe the problem is line below -----------------------------
if (isset($_POST['option_meno'][$row['meno']])) {
echo "<input type='checkbox' name='option_meno[".$row['meno']."]' value='".$row['meno']."' checked='checked' />" . $row['meno'];
echo "<br />";
//}
}
else{
echo "<input type='checkbox' name='option_meno[".$row['meno']."]' value='".$row['meno']."' / >" . $row['meno'];
echo "<br />";
}
}
}
else{
$option_meno = array();
echo "<strong>Meno:</strong>";
echo "<br />";
while($row = mysql_fetch_array($result_meno)){
echo "<input type='checkbox' name='option_meno[".$row['meno']."]' value='".$row['meno']."' checked />" . $row['meno'];
echo "<br />";
$option_meno[] = $row['meno'];
}
}
?>
<input type="submit" name="Filtrovat" value="Filtrovat" />
</form>
This way you check for each checkbox individually.
Note: You should always fully declare the checked attribute, like so: checked='checked'

Related

Delete individual lines/rows with PHP button

What I am trying to do is have a PHP page display the contents of a MySQL database and and each line it displays, it give me a delete button so I can delete individual rows. I have the code kind of working. The code delete the lines of code, but not the one I select, instead it deletes the last line and not the one I tell it to delete.
Here is a screenshot, I know it does not look pretty, I was going to clean it up after I get the code working.
HTML:
<?php
// Delete php code
if(isset($_POST['delete_series']))
{
// here comes your delete query: use $_POST['deleteItem'] as your id
$delete = $_POST['delete_series'];
$delete_sql = "DELETE FROM `Dropdown_Series` where `id` = '$delete'";
if(mysql_query($delete_sql, $conn))
{
echo "Row Deleted </br>";
echo "$delete";
};
}
//Insert Code
if(isset($_POST['add_series']))
{
$insert_sql = "INSERT INTO dropdown_series (series) VALUES ('$_POST[add_series]' )";
if(!mysql_query($insert_sql, $conn))
{
die ('Error: ' . mysql_error());
}
echo "Series Added <br><br>";
}
?>
<br />
<h1>Add New Series Title</h1>
<h3>Add New: </h3><br />
<form name = action="add_series.php" method="POST">
<input type = "text" name = "add_series" required/><br /><br />
<input type ="submit" name="submit" value="Add">
</form>
<h3>Current Series: </h3><br />
<?php
//Delete button on each result of the rows
$query = mysql_query("SELECT id, series FROM Dropdown_Series"); // Run your query
// Loop through the query results, outputing the options one by one
echo "<form action='' method='POST'>";
while ($row = mysql_fetch_array($query))
{
echo $row['series'] . " ";
echo $row['id'];
echo "<input type='hidden' name='delete_series' value=' " . $row['id'] . "' />";
echo "<input type='submit' name='submit' value='Delete'>";
//echo $row['series'] . " ". $row['id'] . "<input type='submit' value='delete'>";
echo "<br />";
}
echo "</form>";
?>
Your loop will result in multiple delete_series inputs - within the same form.
You could create separat forms for each option:
while ($row = mysql_fetch_array($query))
{
echo "<form action='' method='POST'>";
// ...
echo "<input type='hidden' name='delete_series' value=' " . $row['id'] . "' />";
echo "<input type='submit' name='submit' value='Delete'>";
// ...
echo "</form>";
}
I believe that a very quick answer would be
while ($row = mysql_fetch_array($query))
{
echo "<form action='' method='POST'>";
echo $row['series'] . " ";
echo $row['id'];
echo "<input type='hidden' name='delete_series' value=' " . $row['id'] . "' />";
echo "<input type='submit' name='submit' value='Delete'>";
//echo $row['series'] . " ". $row['id'] . "<input type='submit' value='delete'>";
echo "<br />";
echo "</form>";
}
If I were you I would prefer injecting some javascript in the logic, and perform the Delete request using an ajax call.
you can refer to this tutorial to get more understanding of what I am refering to https://scotch.io/tutorials/submitting-ajax-forms-with-jquery

Tried to replace $_GET with $_POST, but now it won't display or update

I tried to retype a code of my groupmate, because the 'textarea' in here is going to be bombarded by a whole lot of string and the problem is that the request URI is too long. So I tried to change of all the $_GET to $_POST, because it won't be posted in the URL.
But the problem is that it won't display the input 'text' and 'textarea' in the isset. I don't know whether it's the isset that is the problem or the or the $_POST, but when I return it back to $_GET it works.
PHP Code for displaying the chapters to be updated and the update function.
<?php
if (isset($_POST['submit'])) {
$id = $_POST['cid'];
$title = $_POST['ctitle'];
$body = $_POST['cbody'];
$result = $db->query("UPDATE chapter set chapter_title='$title', chapter_body='$body' where chapter_id='$id'");
}
$result = $db->query("select * from chapter");
while($row = mysqli_fetch_assoc($result)) {
$update = 'chapterid';
echo "<li id='button' class='btn' ><b id='shadow'><a href='chapter1.php?update={$row['chapter_id']}'>{$row['chapter_title']}</b></a></li></button>";
}
?>
PHP code for displaying the input 'text' and 'textarea'.
<?php
if (isset($_POST['update'])) {
$update = $_POST['update'];
$result1 = $db->query("select * from chapter where chapter_id=$update");
while($row1 = mysqli_fetch_assoc($result1)) {
echo "<center>";
echo "<form class='form' method='POST'>";
echo "<h2>Update Form</h2>";
echo "<hr/>";
echo"<input class='input' type='hidden' name='cid' value='{$row1['chapter_id']}'/>";
echo "<br />";
echo "<label>" . "Chapter Title:" . "</label>" . "<br />";
echo"<input class='input' type='text' name='ctitle' value='{$row1['chapter_title']}' />";
echo "<br />";
echo "<label>" . "Chapter Body:" . "</label>" . "<br />";
echo "<textarea rows='15' cols='95' name='cbody'>{$row1['chapter_body']}";
echo "</textarea>";
echo "<br />";
echo "<input class='submit' type='submit' name='submit' value='update' />";
echo "</form>";
echo "</center>";
}
}
if (isset($_POST['submit'])) {
echo '<div class="form" id="form3"><br><br><br><br><br><br>
<Span>Data Updated Successfuly......!!</span></div>';
}
?>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</div><?php
mysqli_close($db);
?>
if (isset($_POST['update'])) {
This line should stay $_GET['update'], because "update" is not part of you form, but part of the url:
<a href='chapter1.php?update={$row['chapter_id']}'

how to store answers from an online examination system to database

I am creating an online examination system where am fetching questions and answers from database and displays options in radio button. But, the problem is if i click save it just saves one answer not answer from all questions
php codes for fetching questions
$quer=" SELECT * FROM questionset ORDER BY RAND() ";
$query=mysqli_query($sql,$quer);
while($row = mysqli_fetch_array($query))
{
$na= $row['qus'];
$opa= $row['opa'];
$opb= $row['opb'];
$opc= $row['opc'];
$opd= $row['opd'];
echo "<div class='pr3'>";
echo "<div id='question'>";
echo $na;
echo "</div>";
echo "<br/>";
echo "<form name='cart' method='post'>";
echo "<input type='radio' name='ans' value='" . $opa. "' onclick='answ(this.value)' >";
echo $opa;
echo "<br/>";
echo "<input type='radio' name='ans' value='" . $opb. "' onclick='answ(this.value)'>";
echo $opb;
echo "<br/>";
echo "<input type='radio' name='ans' value='" . $opc. "' onclick='answ(this.value)'>";
echo $opc;
echo "<br/>";
echo "<input type='radio' name='ans' value='" . $opd. "' onclick='answ(this.value)'>";
echo $opd;
echo "<br/>";
echo "<input type='text' id='ansval' name='ansval' >";
echo "</form>";
echo " </div>";
}
Javascript that updates just one text box
<script>
function answ(answer) {
document.getElementById("ansval").value = answer;
}
</script>
The radio buttons name are all same for all questions. You have to make the radio buttons names dynamically for each answer set. You can use the following code :
$quer=" SELECT * FROM questionset ORDER BY RAND() ";
$query=mysqli_query($sql,$quer);
while($row = mysqli_fetch_array($query))
{
$questionId = $row['questionId']; //primary key of question table
$na= $row['qus'];
$opa= $row['opa'];
$opb= $row['opb'];
$opc= $row['opc'];
$opd= $row['opd'];
echo "<div class='pr3'>";
echo "<div id='question'>";
echo $na;
echo "</div>";
echo "<br/>";
echo "<form name='cart' method='post'>";
echo "<input type='radio' name='ans<?php echo $questionId; ?>' value='" . $opa. "' onclick='answ(this.value,'<?php echo $questionId; ?>')' >";
echo $opa;
echo "<br/>";
echo "<input type='radio' name='ans<?php echo $questionId; ?>' value='" . $opb. "' onclick='answ(this.value,'<?php echo $questionId; ?>')'>";
echo $opb;
echo "<br/>";
echo "<input type='radio' name='ans<?php echo $questionId; ?>' value='" . $opc. "' onclick='answ(this.value,'<?php echo $questionId; ?>')'>";
echo $opc;
echo "<br/>";
echo "<input type='radio' name='ans<?php echo $questionId; ?>' value='" . $opd. "' onclick='answ(this.value,'<?php echo $questionId; ?>')'>";
echo $opd;
echo "<br/>";
echo "<input type='text' id='ansval<?php echo $questionId; ?>' name='ansval<?php echo $questionId; ?>' >";
echo "</form>";
echo " </div>";
}
And You javascript function will be looks like :
<script>
function answ(answer,qId) {
document.getElementById("ansval"+qId).value = answer;
}
</script>
After the answer submit you can get the submitted values in same way. i.e $_POST['ansval'.$questionId]; Before get the value you have to create another loop to get all question Ids.
ID field must be unique
++$counter;
echo "";
$_POST['ansval1'],$_POST['ansval2'],$_POST['ansval3'].....

MySQLi Update Record via Form loaded from PHP and SQL. Database wont update

I am required to create a drop down box which gathers the records from a database to populate the drop down. When one of the values is selected, a form is to be displayed which contains the data relating to the value selected.
The form is to have the function of showing the selected data, but also to update the record in the database when filled out and Submit.
I have created a php file to try and accomplish this, but Im getting errors such as undefined index and unknown column.
I am only new to PHP so this is a big task for me. Could someone have a look at my code and inform me if there are any errors.
Ive been trying to piece code together here and there from the net but its been tricky trying to get it all to work.
I am not getting any errors now after some tweaking, but the record wont update. I get a 'record updated successfully' message but the record isn't updated.
I am pretty sure the lack of a record update is coming down to the ID not getting collected properly via the $q=$row["BearId"] but if I use $q=$_GET["q"] I get nothing but errors. I am not completely positive this is the problem though, that is why Im asking the question here.
I would appreciate any help that you can give. Ive gotten so far with this thing and yet I cant get it to update the record.
EDIT: I have pinpointed the problem down to the id in
$sql = "UPDATE //snip WHERE BearId = '$q'";
$q=$row["BearId"];
If I manually change BearId to equal '1' then the record is updated.
updatebears.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Update Bears</title>
<script>
function showUser(str)
{
if (str=="")
{
document.getElementById("result").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("result").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getvalues.php?q="+str,true);
xmlhttp.send();
}
</script>
<style>
// style elements
</style>
</head>
<body>
<h1>Update Bears</h1>
Select a Bear:
<br />
<select name="bears" onchange="showUser(this.value)">
<option value="">Select a BearId</option>
<?php
$query = "SELECT * FROM bears";
$mysqli = new mysqli('localhost','User','123','bears');
$result = $mysqli->query($query);
while($row = $result->fetch_assoc())
echo '<option value="'.$row["BearId"].'">'.$row["BearId"].'</option>';
?>
</select>
<br />
<?php
$q=$row["BearId"];
$mysqli = new mysqli('localhost','User','123','bears');
$sql = "SELECT * FROM bears WHERE BearId='".$q."'";
if(array_key_exists('_submit_check', $_POST))
{
$weight = $_POST['Weight'];
$sex = $_POST['Sex'];
$type = $_POST['Type'];
$colour = $_POST['Colour'];
$breed = $_POST['BreedId'];
$sql = "UPDATE bears SET Weight = '$weight', Sex = '$sex', Type = '$type', Colour = '$colour', Breed = '$breed' WHERE BearId = '$q'";
if($mysqli->query($sql) === TRUE)
{
echo 'Record updated successfully<br />';
}
else
{
echo $sql.'<br />' . $mysqli->error;
}
$mysqli->close();
}
?>
<br />
<div id="result"></div>
<br />
Click here to Visit Task 2 (Insert Bears) | Click here to Visit Task 3 (Display Bears)
</body>
</html>
getvalues.php
<?php
$q=$_GET["q"];
$mysqli = new mysqli('localhost','User','123','bears');
$sql = "SELECT * FROM bears WHERE BearId='".$q."'";
if($stmt = $mysqli->prepare($sql))
{
$stmt->execute();
$stmt->bind_result($BearId, $Weight, $Sex, $Type, $Colour, $Breed);
while ($stmt->fetch())
{
echo "<form method='post' name='form1' onsubmit='return validateForm()' action='updatebears.php'>";
echo "<p>";
echo "<label for='BreedId'>BreedId:</label>";
echo "<br />";
echo "<select id='BreedId' name='BreedId' />";
echo "<option value='".$Breed."'>".$Breed."</option>";
echo "<option value='1'>1. Polar</option>";
echo "<option value='2'>2. Brown</option>";
echo "<option value='3'>3. Panda</option>";
echo "</select>";
echo "</p>";
echo "<p>";
echo "<label for='Weight'>Weight(kg):</label>";
echo "<br />";
echo "<input type='text' id='Weight' name='Weight' value='".$Weight."' />";
echo "</label>";
echo "</p>";
echo "<p>";
echo "Sex: ";
echo "<br />";
echo "<label for='M'>Male</label><input type='radio' id='M' value='M' name='Sex'";
if($Sex=='M') echo "checked";
echo "/>";
echo "<label for='F'>Female</label><input type='radio' id='F' value='F' name='Sex'";
if($Sex=='F') echo "checked";
echo "/>";
echo "</p>";
echo "<p>";
echo "<label for='Type'>Type:</label> ";
echo "<br />";
echo "<input type='text' id='Type' name='Type' maxlength='100' value='".$Type."' />";
echo "</p>";
echo "<p>";
echo "<label for='Colour'>Colour:</label>";
echo "<br />";
echo "<input type='text' id='Colour' name='Colour' maxlength='20' value='".$Colour."' />";
echo "</p>";
echo "<p>";
echo "<input type='submit' value='Submit' />";
echo "<input type='reset' value='Reset' />";
echo "<input type='hidden' name='_submit_check' value=1 />";
echo "</p>";
echo "</form>";
}
}
else
{
echo 'Unable to connect';
exit();
}
?>
Thanks for the help.
I believe what you need to do is create a hidden input type for the BearId within the getvalues.php file. That way when your form performs the post you can get the BearId from the post as opposed to trying to get it from the $row['BearId']. I'm fairly certain $row['BearId'] is not the same $row['BearId'] that the user selected when he first goes to the getvalues.php form. Have you tried printing $row['BearId'] to html to verify it's a legitimate value?
if(array_key_exists('_submit_check', $_POST))
{
$id = $_POST['BearId']
$weight = $_POST['Weight'];
$sex = $_POST['Sex'];
$type = $_POST['Type'];
$colour = $_POST['Colour'];
$breed = $_POST['BreedId'];
$sql = "UPDATE bears SET Weight = '$weight', Sex = '$sex', Type = '$type', Colour = '$colour', Breed = '$breed' WHERE BearId = '$id'";
if($mysqli->query($sql) === TRUE)
{
echo 'Record updated successfully<br />';
}
else
{
echo $sql.'<br />' . $mysqli->error;
}
$mysqli->close();
}
?>
<h1>getvalues.php</h1>
<?php
$q=$_GET["q"];
$mysqli = new mysqli('localhost','User','123','bears');
$sql = "SELECT * FROM bears WHERE BearId='".$q."'";
if($stmt = $mysqli->prepare($sql))
{
$stmt->execute();
$stmt->bind_result($BearId, $Weight, $Sex, $Type, $Colour, $Breed);
while ($stmt->fetch())
{
echo "<form method='post' name='form1' onsubmit='return validateForm()' action='updatebears.php'>";
echo <input type="hidden" name="BearId" value='".$q."'>
echo "<p>";
echo "<label for='BreedId'>BreedId:</label>";
echo "<br />";
echo "<select id='BreedId' name='BreedId' />";
echo "<option value='".$Breed."'>".$Breed."</option>";
echo "<option value='1'>1. Polar</option>";
echo "<option value='2'>2. Brown</option>";
echo "<option value='3'>3. Panda</option>";
echo "</select>";
echo "</p>";
echo "<p>";
echo "<label for='Weight'>Weight(kg):</label>";
echo "<br />";
echo "<input type='text' id='Weight' name='Weight' value='".$Weight."' />";
echo "</label>";
echo "</p>";
echo "<p>";
echo "Sex: ";
echo "<br />";
echo "<label for='M'>Male</label><input type='radio' id='M' value='M' name='Sex'";
if($Sex=='M') echo "checked";
echo "/>";
echo "<label for='F'>Female</label><input type='radio' id='F' value='F' name='Sex'";
if($Sex=='F') echo "checked";
echo "/>";
echo "</p>";
echo "<p>";
echo "<label for='Type'>Type:</label> ";
echo "<br />";
echo "<input type='text' id='Type' name='Type' maxlength='100' value='".$Type."' />";
echo "</p>";
echo "<p>";
echo "<label for='Colour'>Colour:</label>";
echo "<br />";
echo "<input type='text' id='Colour' name='Colour' maxlength='20' value='".$Colour."' />";
echo "</p>";
echo "<p>";
echo "<input type='submit' value='Submit' />";
echo "<input type='reset' value='Reset' />";
echo "<input type='hidden' name='_submit_check' value=1 />";
echo "</p>";
echo "</form>";
}
}
else
{
echo 'Unable to connect';
exit();
}

using variables in $_post[]

I have been using variable in the name part of the input tag. Now while access answers as selected by users using $_post,It gives error as undefined index.Tell me how to get answers of all questions as selected .
echo "<form method=\"post\" action=\"\">";
$query=mysql_query("select q_detail,q_id from question where category=\"$value2\"",$connection);
if(!$query)
{
echo mysql_error().'query failed';
}
$ans=1;
while($value1=mysql_fetch_array($query))
{
echo "Q-$i"." ";
echo $value1['q_detail']."<br />";
$i++;
$qno=$value1['q_id'];
$query1=mysql_query("select * from answer where ans_id=$qno");
if(!$query1)
{
echo mysql_error().'query failed';
}
while($value2=mysql_fetch_array($query1))
{
$opt=$value2['option1'];
$opt1=$value2['option2'];
$opt2=$value2['option3'];
$opt3=$value2['correct'];
echo "<input type=\"radio\" value=\"$opt\" name=\"$ans\">";
echo "<span class=\"margin\">$opt</span>";
echo "<input type=\"radio\" value=\"$opt1\" name=\"$ans\">";
echo $opt1." ";
echo "<input type=\"radio\" value=\"$opt2\" name=\"$ans\">";
echo $opt2." ";
echo "<input type=\"radio\" value=\"$opt3\" name=\"$ans\">";
echo $opt3." <br /><br />";
$ans++;
}
}
echo"<input type=\"submit\" name=\"submit\" value=\"submit\">";
echo "</form>";
You can make the name of input as array, e.g.:
<input type="radio" value="Blah" name="answers[]" />
and in php code you can access this using the following code:
foreach($_POST['answers[]'] as $answer)
{
echo $answer;
}
Enclose the non-numeric value with single quotes.
$query=mysql_query("select q_detail,q_id
from question where category='$value2'");
Try this:
$ans=1;
if(isset($_POST))
{
echo $_POST['radio_' . $ans];
}
echo "<form method=\"post\" action=\"\">";
$query=mysql_query("select q_detail,q_id from question where category=\"$value2\"",$connection);
if(!$query)
{
echo mysql_error().'query failed';
}
while($value1=mysql_fetch_array($query))
{
echo "Q-$i"." ";
echo $value1['q_detail']."<br />";
$i++;
$qno=$value1['q_id'];
$query1=mysql_query("select * from answer where ans_id=$qno");
if(!$query1)
{
echo mysql_error().'query failed';
}
while($value2=mysql_fetch_array($query1))
{
$opt=$value2['option1'];
$opt1=$value2['option2'];
$opt2=$value2['option3'];
$opt3=$value2['correct'];
echo "<input type=\"radio\" value=\"$opt\" name=\"radio_$ans\">";
echo "<span class=\"margin\">$opt</span>";
echo "<input type=\"radio\" value=\"$opt1\" name=\"radio_$ans\">";
echo $opt1." ";
echo "<input type=\"radio\" value=\"$opt2\" name=\"radio_$ans\">";
echo $opt2." ";
echo "<input type=\"radio\" value=\"$opt3\" name=\"radio_$ans\">";
echo $opt3." <br /><br />";
$ans++;
}
}
echo"<input type=\"submit\" name=\"submit\" value=\"submit\">";
echo "</form>";
I've added the if(isset($_POST)) and before the name I've added some text, because a name as a integer, can be used as a integer index in PHP. Array's can be called like
$ar = array("Name" => "VALUE");
echo $ar[0]; // Outputs VALUE
echo $ar["Name"]; // Outputs VALUE
Will both output "VALUE". So what you're trying to do. Is getting the value of index 1 instead of key 1.
You have to use $_POST['actual radiobutton name'], i. e. whatever the content of $ans is at the time of the echoing.
You can also debug your form after submitting by using this code:
echo "<pre>";
print_r($_POST);
echo "</pre>";
This will show you the contents of the $_POST data so you can see if values are being passed correctly.

Categories