visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: radio button error


By: mazkot U.S.A.  Date: 18/03/2003 00:00:00  English  Points: 20 Status: Answered
Quality : Excellent
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="<A HREF="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0">http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0</A>" width="616" height="50">
<param name="movie" value="App_personal.swf">
<param name="quality" value="high">
<embed src="page3" quality="high" pluginspage="<A HREF="http://www.macromedia.com/go/getflashplayer">http://www.macromedia.com/go/getflashplayer</A>" 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="<A HREF="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0">http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0</A>" width="616" height="50">
<param name="movie" value="App_personal.swf">
<param name="quality" value="high">
<embed src="work" quality="high" pluginspage="<A HREF="http://www.macromedia.com/go/getflashplayer">http://www.macromedia.com/go/getflashplayer</A>" 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>


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

By: carchitect Date: 18/03/2003 18:33:00 English  Type : Comment
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="<A HREF="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0">http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0</A>" width="616" height="50">
<param name="movie" value="App_personal.swf">
<param name="quality" value="high">
<embed src="page3" quality="high" pluginspage="<A HREF="http://www.macromedia.com/go/getflashplayer">http://www.macromedia.com/go/getflashplayer</A>" 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="<A HREF="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0">http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0</A>" width="616" height="50">
<param name="movie" value="App_personal.swf">
<param name="quality" value="high">
<embed src="work" quality="high" pluginspage="<A HREF="http://www.macromedia.com/go/getflashplayer">http://www.macromedia.com/go/getflashplayer</A>" 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>


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

By: VGR Date: 18/03/2003 18:46:00 English  Type : Comment
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
By: mazkot Date: 19/03/2003 17:07:00 English  Type : Comment
the value of the radio button is given if thereare results.
By: VGR Date: 19/03/2003 18:36:00 English  Type : Comment
I think you don't read me
By: mazkot Date: 20/03/2003 02:54:00 English  Type : Comment
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?
By: VGR Date: 20/03/2003 05:00:00 English  Type : Comment
of course you can.
But your code show only ONE radiobutton, not a selection (unless I need new glasses 8-)


By: mazkot Date: 20/03/2003 12:49:00 English  Type : Comment
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.


By: VGR Date: 20/03/2003 18:58:00 English  Type : Comment
could you show me the HTML resulting page generated by this script, for a dataset of , say, three results ?
By: mazkot Date: 21/03/2003 20:03:00 English  Type : Comment
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

By: VGR Date: 21/03/2003 20:38:00 English  Type : Comment
just make "right-click"/"view (frame/page) source", copy-paste here the relevant part (the FORM)

thanks
By: mazkot Date: 21/03/2003 20:57:00 English  Type : Comment
<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>
By: VGR Date: 21/03/2003 21:11:00 English  Type : Comment
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

By: mazkot Date: 21/03/2003 21:38:00 English  Type : Comment
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.

By: VGR Date: 21/03/2003 23:08:00 English  Type : Comment
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
";
echo "radiobutton value = '$ipntr'
";
?>
By: mazkot Date: 23/03/2003 14:07:00 English  Type : Comment
the value has been passed. now the next question is getting the values from the array.
By: VGR Date: 24/03/2003 23:40:00 English  Type : Comment
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
By: mazkot Date: 25/03/2003 07:56:00 English  Type : Comment
the correct value of the radio button is returned..

how about using sessions for getting the value of the array?
By: VGR Date: 25/03/2003 20:01:00 English  Type : Comment
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
By: mazkot Date: 25/03/2003 20:50:00 English  Type : Comment
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?

By: VGR Date: 25/03/2003 21:47:00 English  Type : Answer
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

Do register to be able to answer

EContact
browser fav
page generated in 382.864950 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page