Page 1 of 1

need radio button to set feature pic

Posted: Thu Aug 02, 2007 9:25 am
by gregorious
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/c ... page02.jpg

here is the form code

Code: Select all

<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>


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.

Code: Select all

$_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";
}


I get this: Error UPDATING Feature Picture!Query was empty

.

Posted: Thu Aug 02, 2007 10:34 am
by VladSun
You need to check the value of $_POST['featurepic']. I.e.

Code: Select all

<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: Select all

$value = $_POST['featurepic'];  
                       
if ($value == 'yes') 
{
  // SQL insert statment here
}
Also you have to put the mysql_query() in the if-statement.

Thanks VladSun for the SOLUTION!

Posted: Thu Aug 02, 2007 11:14 am
by gregorious
Thanks VladSun, that did the trick! And it makes sense to me; I have been reading manuals, forums, and online tutorials but nothing made sense until your message.

Code: Select all

<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: Select all

$_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"; 
}

Posted: Thu Aug 02, 2007 11:39 am
by VladSun
You still have to move the mysql_query() *into* the if statement:

Code: Select all

$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";
  } 
}