need radio button to set feature pic

Discussion in 'PHP' started by gregorious, Aug 2, 2007.

  1. #1
    My form has a YES NO radio button feature that sets the "FEATURE PIC": YES NO - and NO is the checked default.

    Here is an image of the form http://www.forthosewhowait.com/images/cms-editpage02.jpg

    here is the form code

    
    <td width='160' align='left' valign='top'><span class='caption_cap'>Feature Picture</span><br>
    <input name='featurepic' type='radio' value='<?php $image_res_id;?>' ><span class='caption_cap'>yes</span>
    <input name='featurepic' type='radio' value='<?php $resfeaturepic;?>' checked='checked' ><span class='caption_cap'>no</span></td>            
    
    HTML:
    The redisdential table has a field called res_feature_pic, it holds the image id of the feature picture ($imageid). When the admin selects YES and SUBMIT, the current picture being edited gets its $imageid written to res_feature_pic

    The PHP coding is the mystery.

    
    $_POST['featurepic']; 	
    			
    if ($image_res_id == 'checked') {
    						  
    $setfeaturepic = "UPDATE residential SET 
    	res_feature_pic='$imageid' 
    	WHERE res_id='$id'"; }
    				  			  
    if (!mysql_query($setfeaturepic)) {
    echo "<p>Error UPDATING Feature Picture!" 
    . mysql_error() . "Call webmaster";
    }		
    
    PHP:
    I get this: Error UPDATING Feature Picture!Query was empty

    .
     
    gregorious, Aug 2, 2007 IP
  2. adsblog

    adsblog Active Member

    Messages:
    659
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    70
    #2
    print the query and see what is content of your sql query when you submit form .

    print $setfeaturepic;
     
    adsblog, Aug 2, 2007 IP
  3. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #3
    
    <?php $image_res_id;?>
    <?php $resfeaturepic;?>
    
    Code (markup):
    First you need to ECHO or PRINT these to be able to output the values into a form value field.

    if ($image_res_id == 'checked') {
    Code (markup):
    Did you ever set the value for $image_res_id to the posted value of the form?

    res_feature_pic='$imageid' 
    Code (markup):
    I think you are doing the check box form wrong. It will only return the value that is checked and not all the values you put the values of the check box for. So the above will not work if one is checked and the other is not check.
     
    exodus, Aug 2, 2007 IP
  4. gregorious

    gregorious Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    the form type is a radio button so there is no need to echo/print these values in the form.

    $imageid is a passed value from the previous page. And a hidden input in the form <-- learned that one the hard way

    Not quite sure what you mean here. (And you may know this, but, checkboxes allow mutiple sellctions and radio buttons allow one in many sellections).
     
    gregorious, Aug 2, 2007 IP
  5. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #5
    <input name='featurepic' type='radio' value='<?php $image_res_id;?>' ><span class='caption_cap'>yes</span>
    <input name='featurepic' type='radio' value='<?php $resfeaturepic;?>' checked='checked' ><span class='caption_cap'>no</span>
    Code (markup):
    Then why do you have '<?php $image_res_id;?>' and '<?php $resfeaturepic;?>' as the values? They are not doing nothing for it then.

    Also, I guess with the partional code you are showing then we are unable to determine exactly what the problem is, because

    $_POST['featurepic']; 
    if ($image_res_id == 'checked') {
    Code (markup):
    Just the top $_POST['featurepic']; would error out, because it is not put into anything nor is it being echo'd. We don't know if you read the $image_res_id from the $_POST['xxx'] portion. We can not see if you read the $imageid and $id into your php file correctly. You say you have variables via the hidden input field, but did not show this to us. It makes it that much harder to help you. Sorry..
     
    exodus, Aug 2, 2007 IP
  6. gregorious

    gregorious Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    the variables $image and $id are being passed becasue when I remove the line
    if ($image_res_id == 'checked') {
    Code (markup):
    the form updates and sets the current picture being edited - no matter which radio button is selected.

    So the variables are hot, but getting the form to discriminate between YES and NO is the trick.


    http://forums.digitalpoint.com/showthread.php?t=420718
     
    gregorious, Aug 2, 2007 IP
  7. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #7
    Well, then change the POST to a GET and find out what the form is passing as the value for the radio box's. Then do that for the if('' == $image_rs_id) { portion of the code.
     
    exodus, Aug 2, 2007 IP
  8. gregorious

    gregorious Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I changed my values in the form and created a new IF statement. Thanks for the exodus for the support.

    <td width='160' align='left' valign='top'><span class='caption_cap'>Feature Picture</span><br> 
    <input name='featurepic' type='radio' value='yes' ><span class='caption_cap'>yes</span> 
    <input name='featurepic' type='radio' value='no' checked='checked' ><span class='caption_cap'>no</span></td> 
    Code (markup):
    
    $_POST['featurepic']; 
    
    $value = $_POST['featurepic']; 
    if ($value == 'yes') { 
    
    $setfeaturepic = "UPDATE residential SET 
          res_feature_pic='$imageid' 
          WHERE res_id='$id'";
    }
    
    if (!mysql_query($setfeaturepic)) { 
    echo "<p>Error UPDATING Feature Picture!" 
    . mysql_error() . "Call webmaster"; 
    }
    
    PHP:
    .
     
    gregorious, Aug 2, 2007 IP