Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Radio buttons not echoing
Old 10-06-2008, 09:13 AM Radio buttons not echoing
Junior Talker

Posts: 1
Name: Katie Brown
Trades: 0
I am fairly new to php coding so please bear with me. I have some code that will allow me to take weekly attendance. In my db all the entries are defaulted to Y. So essentially I want to look at my member list and mark the absent members. Right now everything is echoing except the radio buttons.


<?php
$host="*******"; // Host name
$username="****"; // Mysql username
$password="******"; // Mysql password
$db_name="******"; // Database name
$tbl_name="`*********`"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY `Last_Name` ASC";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if(!$result)die(mysql_error());
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">


<tr>
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>First Name</strong></td>
<td align="center"><strong>Last Name</strong></td>
<td align="center"><strong>Sept_08_2008</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? $ID[]=$rows['ID_Number']; ?><? echo $rows['ID_Number']; ?></td>
<td align="center"><? $First_Name[]=$rows['First_Name']; ?><? echo $rows['First_Name']; ?></td>
<td align="center"><? $Last_Name[]=$rows['Last_Name']; ?><? echo $rows['Last_Name']; ?></td>
<td align="center"><? $Sept_08_2008[]=$rows['Sept_08_2008']; ?><?
echo("Yes: <input type='radio' name='Sept_08_2008' value='Y'");
if($Sept_08_2008 == 'Y') {
echo(" checked>");
} else {
echo(">");
}
echo("No: <input type='radio' name='Sept_08_2008' value='N'");
if($Sept_08_2008 == 'N') {
echo(" checked>");
} else {
echo(">");
}
?> </td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
// Check if button name "Submit" is active, do this
if($Submit){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET name='$First_Name[$i]', Last_Name='$Last_Name[$i]', Sept_08_2008='$Sept_08_2008[$i]' WHERE ID_Number='$ID_Number[$i]'";
$result1=mysql_query($sql1);
}
}

if($result1){
header("location:attendance.php");
}
mysql_close();
?>
clintonkatie is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-06-2008, 11:43 AM Re: Radio buttons not echoing
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
radio buttons (and check boxes) will ONLY return a value when they are checked
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-06-2008, 12:14 PM Re: Radio buttons not echoing
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
Dealing specifically with your echoing of checked/ unchecked problem. You need to be looking at the value of $rows['Sept_08_2008']



PHP Code:
<?php
$host
="*******"// Host name
$username="****"// Mysql username
$password="******"// Mysql password
$db_name="******"// Database name
$tbl_name="`*********`"// Table name

// Connect to server and select databse.
mysql_connect("$host""$username""$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY `Last_Name` ASC";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if(!
$result)die(mysql_error());
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">


<tr>
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>First Name</strong></td>
<td align="center"><strong>Last Name</strong></td>
<td align="center"><strong>Sept_08_2008</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? $ID[]=$rows['ID_Number']; ?><? echo $rows['ID_Number']; ?></td>
<td align="center"><? $First_Name[]=$rows['First_Name']; ?><? echo $rows['First_Name']; ?></td>
<td align="center"><? $Last_Name[]=$rows['Last_Name']; ?><? echo $rows['Last_Name']; ?></td>
<td align="center"><? $Sept_08_2008[]=$rows['Sept_08_2008']; ?><label>Yes<input name="Sept_08_2008" type="radio" value="Y" <?php if($rows['Sept_08_2008'] == 'Y') { 
echo
"checked";
 } 
?> /></label>
<label>No<input name="Sept_08_2008" type="radio" value="N"  <?php if($rows['Sept_08_2008'] == 'N') {
echo
"checked";
 } 
?> /></label>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
// Check if button name "Submit" is active, do this
if($Submit){
for(
$i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET name='$First_Name[$i]', Last_Name='$Last_Name[$i]', Sept_08_2008='$Sept_08_2008[$i]' WHERE ID_Number='$ID_Number[$i]'";
$result1=mysql_query($sql1);
}
}

if(
$result1){
header("location:attendance.php");
}
mysql_close();
?>

Last edited by maxxximus; 10-06-2008 at 12:18 PM..
maxxximus is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Radio buttons not echoing
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.40100 seconds with 12 queries