User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 429,885 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,298 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 688 | Replies: 5
Reply
Join Date: Jan 2008
Posts: 26
Reputation: pancgom is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
pancgom pancgom is offline Offline
Light Poster

Radio button insert and retrieve

  #1  
Apr 16th, 2008
Hi,

I have 2 radio buttons which needs to submit a checked value to the database and then retrieve the same when called back in to display...any idea where i can get an example for this..

thanks a lot..
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 554
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 57
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Posting Pro

Re: Radio button insert and retrieve

  #2  
Apr 16th, 2008
can you post the form code so I can make the php code based on that.
Reply With Quote  
Join Date: Jan 2008
Posts: 26
Reputation: pancgom is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
pancgom pancgom is offline Offline
Light Poster

Re: Radio button insert and retrieve

  #3  
Apr 16th, 2008
Originally Posted by kkeith29 View Post
can you post the form code so I can make the php code based on that.



<?php
include 'init.php';

if (!is_authed())
{
        header("Location: http://xxxxxxxx/login.php?fail=3");
        exit;
}
$ID = $_SESSION['ID'];

$results = mysql_query("SELECT * FROM `WorkExperience` WHERE ID=$ID");
$row = mysql_num_rows($results);
if($row == 0)
{
        mysql_query("INSERT INTO `WorkExperience` (ID) VALUES ('$ID')");
}

if($_POST['save'] || $_POST['next'])
{



$WorkExperienceYesNo = $_POST['WorkExperienceYesNo'];



$query = "UPDATE `WorkExperience` SET WorkExperienceYesNo='$WorkExperienceYesNo'' WHERE ID=$ID";
mysql_query($query);
}

if($_POST['next'])
{
        header("Location: http://xxxxxxx/pg7.php");
        exit();
}

$query = "SELECT * FROM `WorkExperience` WHERE ID=$ID";
$results = mysql_query($query);
$data = mysql_fetch_array($results);

$WorkExperienceYesNo = $data['WorkExperienceYesNo'];


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<TITLE>Graduate Admission System (Research Programme)</TITLE>

<link href="CSS/GraduateProgram.css" rel="stylesheet" type="text/css">

</head>

<body bgcolor="#FFFFFF" topmargin="0">

<table width=1000 align="center" border="0" cellspacing="0" cellpadding="0" bgcolor="#FF6600">
    <tr>
      <td bgcolor="#FFFFFF"><img src="images/xxxx.png" alt="xxxxxxx" width="450" height="92"></td>
    </tr>
</table>
 
  <br>
<table width=1000 border="0" align="center" cellpadding="3" cellspacing="0" bgcolor=white style="border:1px solid #999999;" valign=top>
  <TR>
    <td height="30" colspan=3 align="left" valign="middle" bgcolor=#ff9933 class="BodyTextHeaders" >Section VII - Employment History</td>
  </TR>
  <TR>
    <td colspan=3 align="left" valign="top" bgcolor=white class="BodyText" > Application Number :</td>
  </TR>
  <TR>
    <td colspan=3 align="left" valign="top" bgcolor=white class="BodyText" > Applicant Name :</td>
  </TR>
  <TR>
    <td colspan=3 align="left" valign="top" bgcolor=white class="BodyText" > Please note that only personal details can be amended.
      For amendments on other data, please contact the 
    administrator for assistance. </td>
  </TR>
  <TR>
    <td colspan=3 align="left" valign="top" bgcolor=white class="BodyText" > Items indicated with an asterisk * are mandatory. </td>
  </TR>
  <TR>
    <td colspan=3 align="left" valign="top" bgcolor=white class="BodyText" >Items indicated with a + are necessary for that section</td>
  </TR>
</TABLE>
  <br>


<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" name="pg6.php"> 
  <TABLE  border=0 ALIGN="center" cellpadding = 3 cellspacing = 0  width="1000" style="border:1px solid #999999;">



<TR>
<td width="136%" height="30" align="left" bgcolor=#ff9933 class="BodyTextHeaders">
			
			(A) Work Experience (Last 5 Years)	</td>
</TR>



<TR>
<td valign="topleft" bgcolor=#E8E8E8 class="BodyText" >
			
			Have you had any work experience relating to your proposed area of research?

              <input type="radio" name="WorkExperienceYesNo" value="Yes" "<?=$WorkExperienceYesNo?>"  >
              Yes
              <input type="radio" name="WorkExperienceYesNo" value="No" "<?=$WorkExperienceYesNo?>"  checked>
              No    </td>
</TR>
</TABLE>
  <br />

<div id="div"></div>

  <table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <th scope="col"><input type="button" class="BodyText"  onclick="generateRow()" value="Add More Work Experience's" /></th>
    </tr>
  </table>
  <BR>
  
  <TABLE  border=0 ALIGN="center" cellpadding = 3 cellspacing = 0 width="1000" style="border:1px solid #999999;">
    <TR>
      <td height="30" align="left" valign="middle" bgcolor=#ff9933 class="BodyTextHeaders">Important Notes</td>
    </TR>
    <TR>
      <td height="100" align="left" valign="middle" bgcolor=white><ul>
          <li class="BodyText">If you have entered information in the above
          section, please click the "Save Changes" button. </li>
        <li class="BodyText"> If no information is updated, please click "Next Section" button. </li>
        <li class="BodyText">Clicking the "Main Menu" button will bring
        you back to the screen listing all sections.</li>
        <li><span class="BodyText">Please click the "Log Out" button to exit.</span><br>
        </li>
      </ul></td>
    </TR>
  </TABLE>
  
  <div align="center">
    <p><br>
      <input name="next" type="submit" class="BodyText" id="Proceed" value="Proceed to Next Section">
      <input name="save" type="submit" class="BodyText"  value="Save Changes">
      <input name="reset" type="reset" class="BodyText" id="reset" value="Clear Form">
      <input name="logout" type="submit" class="BodyText"  value="Logout">
  </div>

</form>

  

</p>
    <p align="center">7/12<br>
    </p>


</BODY>
</HTML>
Reply With Quote  
Join Date: Mar 2008
Posts: 84
Reputation: queenc is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 3
queenc's Avatar
queenc queenc is offline Offline
Junior Poster in Training

Re: Radio button insert and retrieve

  #4  
Apr 17th, 2008
<input type="radio" name="WorkExperienceYesNo" value="Yes" >Yes
         <input type="radio" name="WorkExperienceYesNo" value="No">
              No  
when the user clicks either yes or no will get insert....use ordinarry insert query
Reply With Quote  
Join Date: Jan 2008
Posts: 26
Reputation: pancgom is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
pancgom pancgom is offline Offline
Light Poster

Re: Radio button insert and retrieve

  #5  
Apr 17th, 2008
Originally Posted by queenc View Post
<input type="radio" name="WorkExperienceYesNo" value="Yes" >Yes
         <input type="radio" name="WorkExperienceYesNo" value="No">
              No  
when the user clicks either yes or no will get insert....use ordinarry insert query



Hi,

Thanks for you reply..but my need is a bit more complicated than this...i do know how to do this.....

here is what my above code does....

it accepts the input from the form once the user is logged in and authenticated....the values are stored and then retrieved as and when the user needs it....the radio button field has the same name ....i am using the value attrib to insert the user input as you can see from the code...my sql table has only one field set to receive the data from the radio button....below the specific code..

if($_POST['save'] || $_POST['next'])
{ 

$WorkExperienceYesNo = $_POST['WorkExperienceYesNo'];

   <input type="radio" name="WorkExperienceYesNo" value="Yes" "<?=$WorkExperienceYesNo?>" >
              Yes
              <input type="radio" name="WorkExperienceYesNo" value="No" "<?=$WorkExperienceYesNo?>" checked>
              No    </td>
Reply With Quote  
Join Date: Mar 2008
Posts: 84
Reputation: queenc is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 3
queenc's Avatar
queenc queenc is offline Offline
Junior Poster in Training

Re: Radio button insert and retrieve

  #6  
Apr 17th, 2008
R u trying something like this .............
 <?php

$WorkExperienceYesNo="yes";


 if($WorkExperienceYesNo == "yes")
{ ?>
<input type="radio" name="WorkExperienceYesNo" value="Yes" <? echo "CHECKED"; ?>>
              Yes
<input type="radio" name="WorkExperienceYesNo" value="No" > No    </td>
<? }      
    
else
{ ?>
<input type="radio" name="WorkExperienceYesNo" value="Yes">
              Yes
           <input type="radio" name="WorkExperienceYesNo" value="No"  <? echo "CHECKED"; ?>> No    </td>
<? } ?> 
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 8:40 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC