R
Rowjim
Guest
some ideas on how to go about it.? Here is what I have so far. I populate a table dynamically from my database and include check boxes. I need to be able to modify the text fields, then have only the checked rows updated in my db. I am stuck on how to determine which boxes are checked, and then how to post the correct rows to my modify script. I can modify with sql and delete with sql, just do not know how to transfer the data from an html table by checked rows to my other page. Any help would be greatly appreciated. Here is my code. I am not loooking for specific code examples, that would be cheating. I just need to know if what I am doing is possible and some ideas on where to go with it. NOTE: I commented out the session so it will not affect someone trying to view the table.
<FORM METHOD= "post" ACTION= "modify.php">
<?php
// Starting my session
//session_start();
//if (isset($_SESSION['user'])) {
//
//$msg= "You are logged in as $_SESSION[user]";
//}
//else {
//header("Location: login.html");
//}
// Variable for output
$displayBlock = "";
// Variables for db name, connection, and table name
$db_name= "student_surveydb";
$mainTable= "survey_table";
$connection= mysql_connect("localhost", "root", "")
or die(mysql_error());
// Defining bgcolor variable
$bgcolor= 'beige';
// connecting to db
$db= mysql_select_db($db_name, $connection) or die(mysql_error());
// Assigning select statement to variable.
$sql= "SELECT * FROM $mainTable ORDER BY studentID";
// Assigning result
$result= mysql_query($sql, $connection) or die(mysql_error());
$idarray = array("0");
$firstArray= array("first name");
$lastArray= array("last name");
$genArray= array("gender");
$majArray= array("major");
$comArray= array("comments");
$emailArray= array("email");
// While loop to loop through array of results, assigning values as it goes.
while ($row = mysql_fetch_array($result)) {
$id= $row['studentID'];
array_push($idarray, "$id");
$firstName= $row['studentFirst'];
array_push($firstArray, "$firstName");
$lastName= $row['studentLast'];
array_push($lastArray, "$lastName");
$gender= $row['gender'];
array_push($genArray, "$gender");
$major= $row['major'];
array_push($majArray, "$major");
$comments= $row['comments'];
array_push($comArray, "$comments");
$email= $row['email'];
array_push($emailArray, "$email");
$fullName= "$firstName $lastName";
$num= 1;
// Assigning output as table.
$displayBlock .= "
<TABLE BORDER= 1 CELLSPACING= 1 CELLPADDING= 0 WIDTH= 800>
<tr>
<td align= center width= 14% bgcolor= 'silver'><INPUT TYPE= \"checkbox\" NAME= \"checkid\" VALUE= \"$num\"></td>
<td align= center width= 10% bgcolor= '$bgcolor'>$id</td>
<td width= 12% bgcolor= '$bgcolor'><INPUT TYPE= \"text\" SIZE= \"14\" NAME= \"first_name\" VALUE= '$firstName'></td>
<td width= 12% bgcolor= '$bgcolor'><INPUT TYPE= \"text\" SIZE= \"14\" NAME= \"last_name\" VALUE= '$lastName'></td>
<td width= 5% bgcolor= '$bgcolor'><INPUT TYPE= \"text\" SIZE= \"6\" NAME= \"gender\" VALUE= '$gender'</td>
<td width= 12% bgcolor= '$bgcolor'><INPUT TYPE= \"text\" SIZE= \"12\" NAME= \"major\" VALUE= '$major'</td>
<td width= 20% bgcolor= '$bgcolor'><INPUT TYPE= \"text\" SIZE= \"22\" NAME= \"comments\" VALUE= '$comments'</td>
<td width= 20% bgcolor= '$bgcolor'><INPUT TYPE= \"text\" SIZE= \"22\" NAME= \"email\" VALUE= '$email'</td>
</tr>
</table>
";
$num++;
}
$num= 0;
?>
<!--Ending php and starting html-->
<html>
<head>
<title>General Studies Majors</title><!--General Studies title-->
</head>
<body bgcolor= silver>
<!--<p align= right><?php echo "$msg"; ?></p> -->
<TABLE BORDER= 1 CELLSPACING= 1 CELLPADDING= 0 WIDTH= 800> <!--building table to populate-->
<tr bgcolor= "#F08FF4">
<th width= 7%>Modify</th>
<th width= 4%> ID</th>
<th width= 14%>Student First</th>
<th width= 14%>Student Last</th>
<th width= 5%>Gender</th>
<th width= 12%>Major</th>
<th width= 20%>Comments</th>
<th width= 20%>E-mail Address</th>
</tr>
</TABLE>
<?php echo "$displayBlock"; ?><!--outputting my php variable with output-->
<p>
<INPUT TYPE= "submit" NAME= "submit" VALUE= "Modify">
<!--Links to other pages-->
<p align= left><A HREF= "admin_page.php">Return to Admin Page.</A></P>
</FORM
</body>
</html>
<FORM METHOD= "post" ACTION= "modify.php">
<?php
// Starting my session
//session_start();
//if (isset($_SESSION['user'])) {
//
//$msg= "You are logged in as $_SESSION[user]";
//}
//else {
//header("Location: login.html");
//}
// Variable for output
$displayBlock = "";
// Variables for db name, connection, and table name
$db_name= "student_surveydb";
$mainTable= "survey_table";
$connection= mysql_connect("localhost", "root", "")
or die(mysql_error());
// Defining bgcolor variable
$bgcolor= 'beige';
// connecting to db
$db= mysql_select_db($db_name, $connection) or die(mysql_error());
// Assigning select statement to variable.
$sql= "SELECT * FROM $mainTable ORDER BY studentID";
// Assigning result
$result= mysql_query($sql, $connection) or die(mysql_error());
$idarray = array("0");
$firstArray= array("first name");
$lastArray= array("last name");
$genArray= array("gender");
$majArray= array("major");
$comArray= array("comments");
$emailArray= array("email");
// While loop to loop through array of results, assigning values as it goes.
while ($row = mysql_fetch_array($result)) {
$id= $row['studentID'];
array_push($idarray, "$id");
$firstName= $row['studentFirst'];
array_push($firstArray, "$firstName");
$lastName= $row['studentLast'];
array_push($lastArray, "$lastName");
$gender= $row['gender'];
array_push($genArray, "$gender");
$major= $row['major'];
array_push($majArray, "$major");
$comments= $row['comments'];
array_push($comArray, "$comments");
$email= $row['email'];
array_push($emailArray, "$email");
$fullName= "$firstName $lastName";
$num= 1;
// Assigning output as table.
$displayBlock .= "
<TABLE BORDER= 1 CELLSPACING= 1 CELLPADDING= 0 WIDTH= 800>
<tr>
<td align= center width= 14% bgcolor= 'silver'><INPUT TYPE= \"checkbox\" NAME= \"checkid\" VALUE= \"$num\"></td>
<td align= center width= 10% bgcolor= '$bgcolor'>$id</td>
<td width= 12% bgcolor= '$bgcolor'><INPUT TYPE= \"text\" SIZE= \"14\" NAME= \"first_name\" VALUE= '$firstName'></td>
<td width= 12% bgcolor= '$bgcolor'><INPUT TYPE= \"text\" SIZE= \"14\" NAME= \"last_name\" VALUE= '$lastName'></td>
<td width= 5% bgcolor= '$bgcolor'><INPUT TYPE= \"text\" SIZE= \"6\" NAME= \"gender\" VALUE= '$gender'</td>
<td width= 12% bgcolor= '$bgcolor'><INPUT TYPE= \"text\" SIZE= \"12\" NAME= \"major\" VALUE= '$major'</td>
<td width= 20% bgcolor= '$bgcolor'><INPUT TYPE= \"text\" SIZE= \"22\" NAME= \"comments\" VALUE= '$comments'</td>
<td width= 20% bgcolor= '$bgcolor'><INPUT TYPE= \"text\" SIZE= \"22\" NAME= \"email\" VALUE= '$email'</td>
</tr>
</table>
";
$num++;
}
$num= 0;
?>
<!--Ending php and starting html-->
<html>
<head>
<title>General Studies Majors</title><!--General Studies title-->
</head>
<body bgcolor= silver>
<!--<p align= right><?php echo "$msg"; ?></p> -->
<TABLE BORDER= 1 CELLSPACING= 1 CELLPADDING= 0 WIDTH= 800> <!--building table to populate-->
<tr bgcolor= "#F08FF4">
<th width= 7%>Modify</th>
<th width= 4%> ID</th>
<th width= 14%>Student First</th>
<th width= 14%>Student Last</th>
<th width= 5%>Gender</th>
<th width= 12%>Major</th>
<th width= 20%>Comments</th>
<th width= 20%>E-mail Address</th>
</tr>
</TABLE>
<?php echo "$displayBlock"; ?><!--outputting my php variable with output-->
<p>
<INPUT TYPE= "submit" NAME= "submit" VALUE= "Modify">
<!--Links to other pages-->
<p align= left><A HREF= "admin_page.php">Return to Admin Page.</A></P>
</FORM
</body>
</html>