help with form values
Posted: Wed May 26, 2010 10:33 pm
Hi all,
I just wanted to say thankyou to start with to all the contributors and members. The use of a forum such as this provides a NOOB like me hours of lessons and help:-)
Now, onto a small issue that i have faced for the past week.
I have managed to create a database in MySQL and have a small form that is able to pass info to the database. This works great. I can also display the said information in HTML with a checkbox listed beside the ID of each entry so that the entry can be selected.
What i am trying to do, is be able to allow an end user to select the ID via the check box, then select a radio button which has a value of approve or disapprove(1 or 0) and click on submit which should add a 1 or 0 to a value column in the database in line with the ID they have selected.
Here is the current code which allows the user to be able to see the details of the database with the checkboxes:
Adn this is the code i am trying to use in order to pass the values of the radio buttons and the checked boxes back to the database:
I know it's falling down somewhere, im assuming because the value of the chckbox is NOT being passed properly. Then again we know what assuming does ... any help here would be greatly appreciated.
I just wanted to say thankyou to start with to all the contributors and members. The use of a forum such as this provides a NOOB like me hours of lessons and help:-)
Now, onto a small issue that i have faced for the past week.
I have managed to create a database in MySQL and have a small form that is able to pass info to the database. This works great. I can also display the said information in HTML with a checkbox listed beside the ID of each entry so that the entry can be selected.
What i am trying to do, is be able to allow an end user to select the ID via the check box, then select a radio button which has a value of approve or disapprove(1 or 0) and click on submit which should add a 1 or 0 to a value column in the database in line with the ID they have selected.
Here is the current code which allows the user to be able to see the details of the database with the checkboxes:
Code: Select all
<?php
$id=$_POST['id'];
$Date=$_POST['Date'];
$name=$_POST['name'];
$email=$_POST['email'];
$Value=$_POST['Value'];
$query="SELECT * FROM $tbl_name";
$result=mysql_query($query);
echo "<b><center>Database Output</center></b><br><br>";
echo "<table border='1'>";
echo "<tr> <th>ID</th>";
echo "<th>Date</th>";
echo "<th>Name</th>";
echo "<th>E-mail</th>";
echo "<th>Value</th></tr>";
while($row = mysql_fetch_assoc($result))
{
// Print out the contents of each row into a table
echo "<tr><td>";
echo "<input type=checkbox name=". $row['id'] . " id=". $row['id'] . " value=". $row['id'] . " />".$row['id'];
echo "</td><td>";
echo $row['Date'];
echo "</td><td>";
echo $row['name'];
echo "</td><td>";
echo $row['email'];
echo "</td><td>";
echo $row['Value'];
echo "</td></tr>";
}
echo "</table>";
if($result){
echo "You have successfully update this entry on the database";
echo "<br>";
echo "<a href='testform.php'> Back to search page</a>";
}
else {
echo mysql_error();
}
?>
Code: Select all
// variables
$fields['1'] = false;
$fields['0'] = false;
$fields[$_POST['update']] = true;
$id=$_POST['id'];
//sql queries
mysql_query($query);
$query="INSERT INTO $tbl_name (Value) VALUES ('$fields[1]', '$fields[0])'";
$result=mysql_query($query);
?>
<input type="radio" name="update" id="fields" value="1" />
Approve
<input type="radio" name="update" id="fields" value="0" />
Disapprove</p>
<p>
<input type="submit" name="button" id="button" value="Update the Database" />