Jump to content


Photo

Updating field thru checkbox in a list


  • Please log in to reply
5 replies to this topic

#1 nestorvaldez

nestorvaldez
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 02 October 2006 - 07:11 PM

Hi...
I need to update an status Field in my table..
I have a List (select query) and one of the field in thelist is a checkbox form (this checkbox is a field in the table) I just need to adjust the status. If I marked the checkbox it save 1 and if it is unmarked it it will save 0. I use a bottom at the end of the form to make this update.
I found some code, but it doesn't  work.. I will show it, I hope I could get some help here.

This is some code in the List:

$updatelink="<p align=\"right\"><a href=\"actstatus.php?personal=$id&did=$did\">
<p align=\"right\"><img border=\"0\" src=\"../../images/actstatus.jpg\"alt=\"Update Docs Status\">";
echo ("$updatelink");

[actstatus.php]
<?php
include("../../functions/db.php");
$personal = $_GET['personal'];
$did = $_REQUEST['did'];


foreach ($did as $key => $value){
$p = "$value";
echo $p;
$query = mysql_query("UPDATE regdocu SET RDOC_STATUS=  WHERE RDOC_PERSONAL='$personal' AND RDOC_DOCU='$did'");
    }
if(!$query){
echo '<p><b><font face="Arial" color="#CE0808" style="font-size: 9pt">Error<span lang="es-do">:</span> </font></b>
<font face="Arial" style="font-size: 9pt" color="#CE0808">No se pudo actualizar status del Documento Contacte el administrador.</font></p>';
} else {
echo ("<meta http-equiv=\"refresh\" content=\"5; url=./fnuevo.php?id=$personal\">");
}

?>

#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 02 October 2006 - 07:22 PM

There is a lot of things that might be the problem here, but the first thing you have to do is tell the query WHAT to set as status:

SET RDOC_STATUS='whatever' WHERE....

#3 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 02 October 2006 - 07:23 PM

Checkboxes don't post (or get either) if they aren't checked. You should use a radio button, select box, or something else instead.

If you it has to be a checkbox, you can remove it from the form and have javascript change the value of a hidden field.

PS > I did read your code (and don't see a checkbox). Is this topic titled correctly?

#4 nestorvaldez

nestorvaldez
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 02 October 2006 - 07:35 PM

Yes I know About the SET in the STATUS, what I need to set is what I check in the checkbox in the list.If mark it I need to move 1 if I dont I what to move 0.
That is the only thing I need to do.. update in the table what i check.
But I dont know if the code is correct? Help me with this.....

#5 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 02 October 2006 - 07:45 PM

you could set a variable based on the existance of that $_POST.

$my_new_var=is_set($_POST['checkboxname']);

if it exists, you get a 1, if not, you get a 0.

#6 nestorvaldez

nestorvaldez
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 02 October 2006 - 09:03 PM

I cant get it..  This is all the code of the two files:
and this is the link of the file to see what I have:
http://www.internati....com/fnuevo.php





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users