• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

radio button error

here's a copy of the page i'm doing. My problem is that I cannot get the value of the radio button. its always zero.


<?
include("../Test/test/initdbase.inc");
session_start();
GLOBAL $isrelname;
GLOBAL $isrelation;
//GLOBAL $irelname;
//GLOBAL $irelation;
//GLOBAL $ipntr;
session_register("ipntr");
session_register("isrelname");
session_register("isrelation");
//$isrelation = Array();
//$isrelname = Array();
//$ipntr=0;
$ictr=0;
$ipntr=0;
/*GLOBAL $woemployer;
GLOBAL $wofro;
GLOBAL $woto;
GLOBAL $wopos;
GLOBAL $ctr;*/
/*$woemployer = ARRAY();
$wofro = ARRAY();
$woto = ARRAY();
$wopos = ARRAY();
$sctr = 0;
$wctr = 0;
$cctr = 0;
$rctr = 0;*/
?>
<html>
<body>
<table width="626" border="1" align=center><!--DWLayoutTable-->
  <tr>
    <td width="616"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="616" height="50">
        <param name="movie" value="App_personal.swf">
        <param name="quality" value="high">
        <embed src="page3" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="616" height="50"></embed></object></td>
  </tr>
  <tr>
    <td>
    <form name="Page3" method="get" action="page3submit.php" onsubmit="return checkban()">

!--ISD employee-->
<table width="626" border="1" align=center>
<tr>
<td width="616"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="616" height="50">
<param name="movie" value="App_personal.swf">
<param name="quality" value="high">
        <embed src="work" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="616" height="50"></embed></object></td>
        </tr>
        <tr>
               <td>
        <table width="100%" border="1">
        <tr bgcolor="#0099CC">
              <td colspan="1%"><div align="center"> </div></td>
            <td width="50%"><div align="center"><font size="2" face="Tahoma"/>Employee Name </font></div></td>
            <td width="49%"><div align="center"><font size="2" face="Tahoma"/>Relationship </font></div></td>
        </tr>
         
<?
$query="Select * from HRIS.ISD_EMPLOYEE";
$result=odbc_exec($connection,$query);
$numrows=odbc_num_rows($result);
if ($numrows != 0)
{
while(odbc_fetch_row($result))
{
if (($ictr%2)==0){echo '<tr bgcolor="#CCCCCC">';}else{ echo '<tr bgcolor="#99CCFF">';}
$isrelname[$ictr]=odbc_result($result,"isrelname");
$isrelation[$ictr]=odbc_result($result,"isrelation");

echo '<td width="1%"><div align="left"><input type="radio" name="ipntr" value ='.$ictr.'>'.$x.'</div></td>';
echo '<td width="50%"><div align="center"><font size="2" face="Tahoma"/>'.$isrelname[$ictr].'</font></div></td>';
echo '<td width="49%"><div align="center"><font size="2" face="Tahoma"/>'.$isrelation[$ictr].'</font></div></td>';
echo "</tr>";
$ictr++;
}      
}
?>
      
<tr>
</tr>
</td>
</tr>
</table>
<div align="center">
<? echo $ipntr; ?>

<input type="button" value=" Add " onclick="Newwin=window.open('isd_employee.php')"  align=center size=50 />
<input type="button" value=" Edit " onclick="Newwin=window.open('edit_isd_employee.php<?echo "?isrelname=".$isrelname[$ipntr]."&isrelation=".$isrelation[$ipntr]."&ipntr=".$ipntr;?>')"  align=center size=50 />
<input type="button" value=" Delete " onclick="Newwin=window.open('del_workexp.php')"  align=center size=50 />
<input type="button" value=" Preview " onclick="Newwin=window.open('list_workexp.php')"  align=center size=50 />


</div>
</form>
</table>
<br>
<tr>
<td height="20"><div align="center">
<input type="button" value="Previous Page " onclick="Newwin=window.open('add_work.php')"  align=center size=50 />
<input type="button" value="Next page "  align=center size=50 /></div></td>
  </tr>
    </table>
  </div>
  <p align="center">&nbsp;</p>
 
</tr>
</form>
</td>
</tr>
</table>
</body>
</html>
0
mazkot
Asked:
mazkot
  • 16
  • 10
  • +1
1 Solution
 
carchitectCommented:
try this

<?
include("../Test/test/initdbase.inc");
session_start();
GLOBAL $isrelname;
GLOBAL $isrelation;
//GLOBAL $irelname;
//GLOBAL $irelation;
//GLOBAL $ipntr;
session_register("ipntr");
session_register("isrelname");
session_register("isrelation");
//$isrelation = Array();
//$isrelname = Array();
//$ipntr=0;
$ictr=0;
$ipntr=0;
/*GLOBAL $woemployer;
GLOBAL $wofro;
GLOBAL $woto;
GLOBAL $wopos;
GLOBAL $ctr;*/
/*$woemployer = ARRAY();
$wofro = ARRAY();
$woto = ARRAY();
$wopos = ARRAY();
$sctr = 0;
$wctr = 0;
$cctr = 0;
$rctr = 0;*/
?>
<html>
<body>
<table width="626" border="1" align=center><!--DWLayoutTable-->
 <tr>
   <td width="616"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="616" height="50">
       <param name="movie" value="App_personal.swf">
       <param name="quality" value="high">
       <embed src="page3" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="616" height="50"></embed></object></td>
 </tr>
 <tr>
   <td>
   <form name="Page3" method="get" action="page3submit.php" onsubmit="return checkban()">

!--ISD employee-->
<table width="626" border="1" align=center>
<tr>
<td width="616"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="616" height="50">
<param name="movie" value="App_personal.swf">
<param name="quality" value="high">
       <embed src="work" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="616" height="50"></embed></object></td>
      </tr>
      <tr>
            <td>
      <table width="100%" border="1">
       <tr bgcolor="#0099CC">
            <td colspan="1%"><div align="center"> </div></td>
           <td width="50%"><div align="center"><font size="2" face="Tahoma"/>Employee Name </font></div></td>
           <td width="49%"><div align="center"><font size="2" face="Tahoma"/>Relationship </font></div></td>
       </tr>
       
<?
$query="Select * from HRIS.ISD_EMPLOYEE";
$result=odbc_exec($connection,$query);
$numrows=odbc_num_rows($result);
if ($numrows != 0)
{
while(odbc_fetch_row($result))
{
if (($ictr%2)==0){echo '<tr bgcolor="#CCCCCC">';}else{ echo '<tr bgcolor="#99CCFF">';}
$isrelname[$ictr]=odbc_result($result,"isrelname");
$isrelation[$ictr]=odbc_result($result,"isrelation");

echo "<td width=1%><div align=left><input type=radio name=ipntr value=$ictr>$x</div></td>";
echo "<td width=50%><div align=center><font size=2 face=Tahoma>$isrelname[$ictr]</font></div></td>";
echo "<td width=49%><div align=center><font size=2 face=Tahoma>$isrelation[$ictr]</font></div></td>";
echo "</tr>";
$ictr++;
}    
}
?>
     
<tr>
</tr>
</td>
</tr>
</table>
<div align="center">
<? echo $ipntr; ?>

<input type="button" value=" Add " onclick="Newwin=window.open('isd_employee.php')"  align=center size=50 />
<input type="button" value=" Edit " onclick="Newwin=window.open('edit_isd_employee.php<?echo "?isrelname=".$isrelname[$ipntr]."&isrelation=".$isrelation[$ipntr]."&ipntr=".$ipntr;?>')"  align=center size=50 />
<input type="button" value=" Delete " onclick="Newwin=window.open('del_workexp.php')"  align=center size=50 />
<input type="button" value=" Preview " onclick="Newwin=window.open('list_workexp.php')"  align=center size=50 />


</div>
</form>
</table>
<br>
<tr>
<td height="20"><div align="center">
<input type="button" value="Previous Page " onclick="Newwin=window.open('add_work.php')"  align=center size=50 />
<input type="button" value="Next page "  align=center size=50 /></div></td>
 </tr>
   </table>
 </div>
 <p align="center">&nbsp;</p>
 
</tr>
</form>
</td>
</tr>
</table>
</body>
</html>
0
 
VGRCommented:
well, given you've only ONE line in a RADIO input, it's rather normal that the selection offers only onechoice (index=0) and that the return value is 0    :D :D

Perhaps you wanted to use a CHECKBOX ?

A RADIO with one value has no sense : it'll always be selected and return 0
0
 
mazkotAuthor Commented:
the value of the radio button is given if thereare results.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
VGRCommented:
I think you don't read me
0
 
mazkotAuthor Commented:
what i'm trying to do is fetch some records from the databse and post it some key colums. I want the user to select only one row, if they want to edit or delete a certain record. that's why i'm using the radio button instead of a check box.

if i understand it right, what vgr is saying.
i cannot create a dynamic selection using radio buttons?
0
 
VGRCommented:
of course you can.
But your code show only ONE radiobutton, not a selection (unless I need new glasses 8-)

0
 
mazkotAuthor Commented:
the radio button is inside a while loop and the values are being supplied by the ictr variable. Is this process wrong?
then could you show me how to make it right.  

the selection range varies depending on number of results found by the query so i placed the radio button inside the while loop.because i don't want to make 10 premade radio buttons and there are only two rows to select from or the result returns more than 10.

0
 
VGRCommented:
could you show me the HTML resulting page generated by this script, for a dataset of , say, three results ?
0
 
mazkotAuthor Commented:
i don't know how to attach a pic file here so the table looks like this. the o is the radio button

   Employee Name   Relationship  
 o   ewan            ewan
 o   SHOBE          ATHENA
 o    test            test
0
 
mazkotAuthor Commented:
i don't know how to attach a pic file here so the table looks like this. the o is the radio button

   Employee Name   Relationship  
 o   ewan            ewan
 o   SHOBE          ATHENA
 o    test            test
0
 
VGRCommented:
just make "right-click"/"view (frame/page) source", copy-paste here the relevant part (the FORM)

thanks
0
 
mazkotAuthor Commented:
<table width="100%" border="1">
        <tr bgcolor="#0099CC">
             <td colspan="1%"><div align="center"> </div></td>
            <td width="50%"><div align="center"><font size="2" face="Tahoma"/>Employee Name </font></div></td>
            <td width="49%"><div align="center"><font size="2" face="Tahoma"/>Relationship </font></div></td>
        </tr>
         
<tr bgcolor="#CCCCCC"><td width="1%"><div align="left"><input type="radio" name="ipntr" value =0></div></td><td width="50%"><div align="center"><font size="2" face="Tahoma"/>ewan</font></div></td><td width="49%"><div align="center"><font size="2" face="Tahoma"/>ewan</font></div></td></tr><tr bgcolor="#99CCFF"><td width="1%"><div align="left"><input type="radio" name="ipntr" value =1></div></td><td width="50%"><div align="center"><font size="2" face="Tahoma"/>SHOBE</font></div></td><td width="49%"><div align="center"><font size="2" face="Tahoma"/>ATHENA</font></div></td></tr><tr bgcolor="#CCCCCC"><td width="1%"><div align="left"><input type="radio" name="ipntr" value =2></div></td><td width="50%"><div align="center"><font size="2" face="Tahoma"/>test</font></div></td><td width="49%"><div align="center"><font size="2" face="Tahoma"/>test</font></div></td></tr>    
<tr>
</tr>
</td>
</tr>
</table>
<div align="center">
0

<input type="button" value=" Add " onclick="Newwin=window.open('isd_employee.php')"  align=center size=50 />
<input type="button" value=" Edit " onclick="Newwin=window.open('edit_isd_employee.php?isrelname=ewan&isrelation=ewan&ipntr=0')"  align=center size=50 />
<input type="button" value=" Delete " onclick="Newwin=window.open('del_workexp.php')"  align=center size=50 />
<input type="button" value=" Preview " onclick="Newwin=window.open('list_workexp.php')"  align=center size=50 />


</div>
</form>
</table>
0
 
mazkotAuthor Commented:
<table width="100%" border="1">
        <tr bgcolor="#0099CC">
             <td colspan="1%"><div align="center"> </div></td>
            <td width="50%"><div align="center"><font size="2" face="Tahoma"/>Employee Name </font></div></td>
            <td width="49%"><div align="center"><font size="2" face="Tahoma"/>Relationship </font></div></td>
        </tr>
         
<tr bgcolor="#CCCCCC"><td width="1%"><div align="left"><input type="radio" name="ipntr" value =0></div></td><td width="50%"><div align="center"><font size="2" face="Tahoma"/>ewan</font></div></td><td width="49%"><div align="center"><font size="2" face="Tahoma"/>ewan</font></div></td></tr><tr bgcolor="#99CCFF"><td width="1%"><div align="left"><input type="radio" name="ipntr" value =1></div></td><td width="50%"><div align="center"><font size="2" face="Tahoma"/>SHOBE</font></div></td><td width="49%"><div align="center"><font size="2" face="Tahoma"/>ATHENA</font></div></td></tr><tr bgcolor="#CCCCCC"><td width="1%"><div align="left"><input type="radio" name="ipntr" value =2></div></td><td width="50%"><div align="center"><font size="2" face="Tahoma"/>test</font></div></td><td width="49%"><div align="center"><font size="2" face="Tahoma"/>test</font></div></td></tr>    
<tr>
</tr>
</td>
</tr>
</table>
<div align="center">
0

<input type="button" value=" Add " onclick="Newwin=window.open('isd_employee.php')"  align=center size=50 />
<input type="button" value=" Edit " onclick="Newwin=window.open('edit_isd_employee.php?isrelname=ewan&isrelation=ewan&ipntr=0')"  align=center size=50 />
<input type="button" value=" Delete " onclick="Newwin=window.open('del_workexp.php')"  align=center size=50 />
<input type="button" value=" Preview " onclick="Newwin=window.open('list_workexp.php')"  align=center size=50 />


</div>
</form>
</table>
0
 
mazkotAuthor Commented:
<table width="100%" border="1">
        <tr bgcolor="#0099CC">
             <td colspan="1%"><div align="center"> </div></td>
            <td width="50%"><div align="center"><font size="2" face="Tahoma"/>Employee Name </font></div></td>
            <td width="49%"><div align="center"><font size="2" face="Tahoma"/>Relationship </font></div></td>
        </tr>
         
<tr bgcolor="#CCCCCC"><td width="1%"><div align="left"><input type="radio" name="ipntr" value =0></div></td><td width="50%"><div align="center"><font size="2" face="Tahoma"/>ewan</font></div></td><td width="49%"><div align="center"><font size="2" face="Tahoma"/>ewan</font></div></td></tr><tr bgcolor="#99CCFF"><td width="1%"><div align="left"><input type="radio" name="ipntr" value =1></div></td><td width="50%"><div align="center"><font size="2" face="Tahoma"/>SHOBE</font></div></td><td width="49%"><div align="center"><font size="2" face="Tahoma"/>ATHENA</font></div></td></tr><tr bgcolor="#CCCCCC"><td width="1%"><div align="left"><input type="radio" name="ipntr" value =2></div></td><td width="50%"><div align="center"><font size="2" face="Tahoma"/>test</font></div></td><td width="49%"><div align="center"><font size="2" face="Tahoma"/>test</font></div></td></tr>    
<tr>
</tr>
</td>
</tr>
</table>
<div align="center">
0

<input type="button" value=" Add " onclick="Newwin=window.open('isd_employee.php')"  align=center size=50 />
<input type="button" value=" Edit " onclick="Newwin=window.open('edit_isd_employee.php?isrelname=ewan&isrelation=ewan&ipntr=0')"  align=center size=50 />
<input type="button" value=" Delete " onclick="Newwin=window.open('del_workexp.php')"  align=center size=50 />
<input type="button" value=" Preview " onclick="Newwin=window.open('list_workexp.php')"  align=center size=50 />


</div>
</form>
</table>
0
 
VGRCommented:
will, this seems to be all right

in your receiving script, $_GET['ipntr'] is always zero ?

What's your PHP version and register_globals setting in php.ini, by the way ? There are warnings in the PHP documentation about using register_globals=On and $_GET and $_SESSION, depending on version.

Also :
session_register("ipntr");

means that your variable ipntr exists in $_SESSION and in $_GET and they are not the same
0
 
mazkotAuthor Commented:
<table width="100%" border="1">
        <tr bgcolor="#0099CC">
             <td colspan="1%"><div align="center"> </div></td>
            <td width="50%"><div align="center"><font size="2" face="Tahoma"/>Employee Name </font></div></td>
            <td width="49%"><div align="center"><font size="2" face="Tahoma"/>Relationship </font></div></td>
        </tr>
         
<tr bgcolor="#CCCCCC"><td width="1%"><div align="left"><input type="radio" name="ipntr" value =0></div></td><td width="50%"><div align="center"><font size="2" face="Tahoma"/>ewan</font></div></td><td width="49%"><div align="center"><font size="2" face="Tahoma"/>ewan</font></div></td></tr><tr bgcolor="#99CCFF"><td width="1%"><div align="left"><input type="radio" name="ipntr" value =1></div></td><td width="50%"><div align="center"><font size="2" face="Tahoma"/>SHOBE</font></div></td><td width="49%"><div align="center"><font size="2" face="Tahoma"/>ATHENA</font></div></td></tr><tr bgcolor="#CCCCCC"><td width="1%"><div align="left"><input type="radio" name="ipntr" value =2></div></td><td width="50%"><div align="center"><font size="2" face="Tahoma"/>test</font></div></td><td width="49%"><div align="center"><font size="2" face="Tahoma"/>test</font></div></td></tr>    
<tr>
</tr>
</td>
</tr>
</table>
<div align="center">
0

<input type="button" value=" Add " onclick="Newwin=window.open('isd_employee.php')"  align=center size=50 />
<input type="button" value=" Edit " onclick="Newwin=window.open('edit_isd_employee.php?isrelname=ewan&isrelation=ewan&ipntr=0')"  align=center size=50 />
<input type="button" value=" Delete " onclick="Newwin=window.open('del_workexp.php')"  align=center size=50 />
<input type="button" value=" Preview " onclick="Newwin=window.open('list_workexp.php')"  align=center size=50 />


</div>
</form>
</table>
0
 
mazkotAuthor Commented:
php 4.2.3
register_globals=on

the code i just gave was when i experimented adding sessions. Even with out the sessions the same problem occurs.

i did not use $get or session cause i added the selection because i'm openning a new window for the edit function.
with the html source the initial value if the first row.
 
<input type="button" value=" Edit " onclick="Newwin=window.open('edit_isd_employee.php?isrelname=ewan&isrelation=ewan&ipntr=0')"  align=center size=50 /> <--html source

<input type="button" value=" Edit " onclick="Newwin=window.open('edit_isd_employee.php<?echo "?isrelname=".$isrelname[$ipntr]."&isrelation=".$isrelation[$ipntr]."&ipntr=".$ipntr;?>')"  align=center size=50 /> <--php source

the problem if when i select the second or third row. the output is still the first row.

i'm totally stuck with this problem.
0
 
mazkotAuthor Commented:
php 4.2.3
register_globals=on

the code i just gave was when i experimented adding sessions. Even with out the sessions the same problem occurs.

i did not use $get or session cause i added the selection because i'm openning a new window for the edit function.
with the html source the initial value if the first row.
 
<input type="button" value=" Edit " onclick="Newwin=window.open('edit_isd_employee.php?isrelname=ewan&isrelation=ewan&ipntr=0')"  align=center size=50 /> <--html source

<input type="button" value=" Edit " onclick="Newwin=window.open('edit_isd_employee.php<?echo "?isrelname=".$isrelname[$ipntr]."&isrelation=".$isrelation[$ipntr]."&ipntr=".$ipntr;?>')"  align=center size=50 /> <--php source

the problem if when i select the second or third row. the output is still the first row.

i'm totally stuck with this problem.
0
 
VGRCommented:
ok, good.

Writing about your first posted code :

first delete all references to HTTP_POST_VATS, _SESSION, _GET or _POST

Keep only your variables.
Delete also all the register_global() calls and all GLOBAL definitions at the beginning, you don't need them at all.

In "page3submit.php", do this (as a test)
<?
echo "received data<BR>";
echo "radiobutton value = '$ipntr'<BR>";
?>
0
 
mazkotAuthor Commented:
the value has been passed. now the next question is getting the values from the array.
0
 
mazkotAuthor Commented:
the value has been passed. now the next question is getting the values from the array.
0
 
mazkotAuthor Commented:
the value has been passed. now the next question is getting the values from the array.
0
 
VGRCommented:
and which value do you get ? always zero, as you mentioned earlier ?

If not, then you have the index (0-based) in the array of rzdiobuttons

If you need the values of the array used to build the FORM, then either :
-re-query to get the same values
-pass the array as a "type=hidden" input from the FORM
0
 
mazkotAuthor Commented:
the correct value of the radio button is returned..

how about using sessions for getting the value of the array?
0
 
VGRCommented:
well, do this just before writing the FORM that will send the user to the next page (where the correct radiobutton value is returned and not-always-zero, thanks to me :D )

$_SESSION['valuesarray']=$yourArrayName;

and in the receiving script, having $ipntr, you will have the corresponding value of the selection in $_SESSION['valuesarray'][$ipntr]

that's all
0
 
mazkotAuthor Commented:
hope this is correct.. assuming the arrayname is $isrelname

session_register("valuesarray"); <--topmost of script
.
.
.
.
.
$_session['valuesarray']=$isrelname;<--near the button script.


do i need to initialize $isrelname as array?
0
 
VGRCommented:
it would be better. Note also that if you hadn't register_globals=On it would be worse 8-)

so do :
<?
session_start();
// some stuff
$isrealname=array();
session_register("isrealname");
// populate $isrealname
// no need to register it again
// no need to use $_SESSION[]
// $isrealname[] will be available in your next scripts (with session_start(); ) thanks to register_globals=On
//that's it
0
 
snoyes_jwCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Accept: VGR {http:#8203588}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

snoyes_jw
EE Cleanup Volunteer
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 16
  • 10
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now