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
Dynamic Radio Buttons Not Updating into database
Old 12-23-2008, 01:06 AM Dynamic Radio Buttons Not Updating into database
PHPnoob's Avatar
Junior Talker

Posts: 1
Name: Diana
Trades: 0
Hi Everyone,

Im new here, but i seriously need help. Am trying to create an attendance form that require 3 radio buttons per name.

The data from the table is extracted from the database. Everything works fine, cept when i try to insert or update the database, nothing works.

I've provided the update code too. Hope someone could help me.. its been 3days im hogged onto it...
Thks in advance!

As shown, this is the code for attendance.
<?php
// Make a MySQL Connection
$id="$_SESSION[SESS_MEMBER_ID]";
$username="";
$password="";
$database="";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$my_t=getdate(date("U"));
print("$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]");
function querysql() {
$query = "SELECT studentName, studentClass, studentID FROM students WHERE studentClass ='4.1'";

$result = mysql_query($query) or die(mysql_error());
$query1 = "";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array($result)){

$qname = $row['studentID'];
$query1 .= "<tr><td>";
$query1 .= $row['studentName'];
$query1 .= "</td><td>";
$query1 .= $row['studentID'];
$query1 .= "</td><td>";
$query1 .= $row['studentClass'];
$query1 .= "</td>";
$query1 .= "<td><input type=\"radio\" class=\"attendance\" value=\"Present\" name=\"$qname\">
Present
<input type=\"radio\" class=\"attendance\" value=\"Absent\" name=\"$qname\">
Absent
<input type=\"radio\" class=\"attendance\" value=\"Status\" name=\"$qname\">
Status
</td></tr>";

}
return $query1;
}
// #test is tr info of student followed by radio button of name = studentid
$test = querysql();//call function querysql
?>
<html>
<head>
<title>Student Attendance List</title>
</head>
<body>
<h1>Student Attendance</h1>
<form action="update.php" method="post" >
<table border='1'>
<tr> <th>Name</th> <th>Student ID</th> <th>Student Class</th> <th>Attendance</th>
<?= $test ?>
<td></td> <td></td> <td></td> <td><input type="submit" value="enter"></td></tr>
</table>
</form>
<hr>
Copyrighted DJ Inc
</body>
</html>

This is the update code:
<?php
$studentName = $_POST['studentName'];
$studentID = $_POST['studentID'];
$studentClass = $_POST['studentClass'];
$attendance = $_POST['attendance'];
$userdate = $_POST['my_t'];
$username="";
$password="";
$database="";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "UPDATE students SET studentName = '$studentName', studentClass = '$studentClass', attendance = '$attendance' WHERE studentID = '$qname'";
mysql_query($query);
echo "Record Updated";
mysql_close();
?>
PHPnoob is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-23-2008, 03:24 AM Re: Dynamic Radio Buttons Not Updating into database
Super Spam Talker

Latest Blog Post:
PSD Squirrel Launched
Posts: 932
Trades: 7
Hi there,

I think I can see your error - that or I'm still half a sleep ...

Check your HTML in your browser, do a view source and see is the radio boxes actually have a name assigned to them, because in the code above you have ..

Code:
<input type=\"radio\" class=\"attendance\" value=\"Absent\" name=\"$qname\">
But I cannot see anywhere in your code where the variable $qname is defined, so you are not actually passing a name to the radio fields.

Additionally you have in your update code ...
Code:
... WHERE studentID = '$qname'";
Yet $qname is not defined when you define all of your $_POST variables,so you will also need to take care of that.

If you need anymore help just let me know, best of luck.

Sir P
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Sir P is offline
Reply With Quote
View Public Profile Visit Sir P's homepage!
 
Reply     « Reply to Dynamic Radio Buttons Not Updating into database
 

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.10908 seconds with 12 queries