need radio button to set feature pic

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gregorious
Forum Commoner
Posts: 34
Joined: Wed Aug 23, 2006 9:55 am
Location: Orlando, FL

need radio button to set feature pic

Post 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

.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
gregorious
Forum Commoner
Posts: 34
Joined: Wed Aug 23, 2006 9:55 am
Location: Orlando, FL

Thanks VladSun for the SOLUTION!

Post 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"; 
}
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post 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";
  } 
}
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply