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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Part of query is failing

Status
Not open for further replies.

frozenpeas

Technical User
Sep 13, 2001
893
CA
Hello,

I am updating a record in my db with the following line (using PHP/MySQL):

Code:
$query = "UPDATE users SET name='$name',level='$level',active='$active' WHERE id='$id'";

The trouble spot is the value for 'level'. This can be one of two options, 'limited' or 'full'. For some reason, I can change it from 'limited' to 'full' but not the inverse.

The form bits that are the source of the value are:

Code:
<input name="level" type="radio" value="limited"<?php if($row['level']=="limited"){echo " checked";}?>>

Code:
<input name="level" type="radio" value="full"<?php if($row['level']=="full"){echo " checked";}?>>

Am I missing something obvious or is something strange going on?

Thanks for your help.

frozenpeas
--
Micfo.com Affiliate Program
 
you need to have array of input name for checkbox
e.g.
Code:
<?php
$lchkstatus = "" ;
$fchkstatus = "" ;
if($row['level']=="limited"){ 
 $lchkstatus = "CHECKED" ;
}
else {
 $fchkstatus = "CHECKED" ;
}
?>

<input name="level" type="radio" value="limited" <?php echo $lchkstatus ;?>>

<input name="level" type="radio" value="full" <?php echo  $fchkstatus; ?>>

Also View the HTML source and output a query to debug.


--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
oops
it should be
Code:
<input name="level[b][][/b]" type="radio" value="limited" <?php echo $lchkstatus ;?>>

<input name="level[b][][/b]" type="radio" value="full" <?php echo  $fchkstatus; ?>>

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Thanks, Spookie. But the issue is not with the radio buttons being checked. It is with the data being written (or not) to the database.

I tried your method anyway, but the problem still occurs.

I am able to set another value with radio buttons. Everything is the same except the input name and value name. But this one will work only from 'limited' to 'full' and not the inverse. Is one of these a reserved word for a MySQL function perhaps?

Thanks again.

frozenpeas
--
Micfo.com Affiliate Program
 
Have you done what spookie suggested:
Spookie said:
...
Also View the HTML source and [red]output a query to debug.[/red]
...
Before running the query echo it out:
Code:
echo $query;

Is it formed correctly?
If you try to run it from a Gui i.e MYSLQ Query Browser, does it run o.k. or does it come back with an error of some sort???


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
$query outputs:
Code:
UPDATE users SET name='Test Account',level='full',active='1' WHERE id='7'

This happens when this radio button is checked:
Code:
<input name="level" type="radio" value="limited">

So I changed the query to use $_POST['level'] instead (which is probably a good idea anyway). But I am really curious as to why this failed for only one element and one value.

Thank you all for your help.

frozenpeas
--
Micfo.com Affiliate Program
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top