Xtremer360 Posted November 25, 2009 Share Posted November 25, 2009 I want to make a way so that instead of having to make more files I can just add some sort of extention onto this file so that it goes to a adddivision function or something and then editdivision. division.php (main file) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="author" content="" /> <title>Untitled 1</title> </head> <body> <h1 class="backstage">Division Management</h1><br /> <h2 class=backstage>Divisions :: <a href="#">Add New</a></h2><br /> <?php { $query = "SELECT * FROM efed_list_divisions ORDER BY `name`"; $result = mysql_query ( $query ); // Run The Query $rows = mysql_num_rows($result); if ($rows > 0) { print '<table width="100%" class="table1">'; print '<tr class="rowheading">'; print '<td> </td>'; print '<td>Name</td>'; print '</tr>'; // Fetch and print all records. $i = 0; $current_row = 0; while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) { $current_row++; $sClass = 'row2'; if ($i ++ & 1) { $sClass = 'row1'; } printf ( "<tr class=\"%s\">", $sClass ); print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"ajaxpage('editdivision', 'content', '".$row['division']."'); return false;\">Edit</a></td>"; printf ( "<td valign=\"top\">%s</td>", $row [name] ); print '</tr>'; } echo '</table>'; } else { print '<span>There are no divisions.</span><br />'; } print '<br />'; returnmain(); } ?> </body> </html> editing division coding <h1 class="backstage">Division Management</h1><br /> <h2 class="backstage">Edit Division</h2><br /> <form name="editdivision" method="post" action="backstage.php" id="editdivision"> <table width="100%" class="table2"> <tr> <td width=\"120\" class=\"rowheading\" valign=\"center\">Division:</td><td class=\"row3\"><input type=\"text\" name=\"division\" class=\"fieldtext490\" value=""></td> </tr> </table><br /> <center> <input type="checkbox" name="deletedivision"><span class="table1heading">Delete Division?</span><br /><br /> <input type="submit" value="Edit Division" class=button name="editdivision"><br /><br /> <input type="button" value="Return to Divisions List" class="button200"><br /><br /> returnmain(); } I also have this function as something that was written before me with a similar script. function getdivisionname($divisionid) { $query = "SELECT divis.name as division FROM efed_list_divisions as divis WHERE divis.id = '$divisionid'"; $result = mysql_query ($query); while ($row = mysql_fetch_assoc($result)) { $division=cleanquerydata($row['division']); return $division; } } Quote Link to comment https://forums.phpfreaks.com/topic/182858-editing-information/ Share on other sites More sharing options...
Tonic-_- Posted November 25, 2009 Share Posted November 25, 2009 Do you mean you are looking to update the fields in the table? Quote Link to comment https://forums.phpfreaks.com/topic/182858-editing-information/#findComment-965144 Share on other sites More sharing options...
Xtremer360 Posted November 25, 2009 Author Share Posted November 25, 2009 I'm trying to figure out if I need a switch with cases or what I need to do so that I can have the list of divisions and then below that the coding for adding divisions form which I have posted yet and the coding for editing divisions which is above. Quote Link to comment https://forums.phpfreaks.com/topic/182858-editing-information/#findComment-965149 Share on other sites More sharing options...
mikesta707 Posted November 25, 2009 Share Posted November 25, 2009 If you want to have a single PHP page that handles a few different form submits you can have each different form have the same name for the submit button but different values. For example. say I had two forms I wanted to submit to one page. Lets call them form1.html and form2.html form1.html <form action="process.php" method="post" > <input type="text" name="Name" /> <input type="submit" name="Submit" value="form1" /> form2.html <form action="process.php" method="post" > <input type="text" name="Password" /> <input type="submit" name="Submit" value="form2" /> then you have a case structure on the process.php page, which would take the value of the submit button as its argument. for example process.php switch($_POST['Submit']){//use the value of the submit button to decide what to do case "form1": //form1 code break; case "form2": //form2 code break; default //error code break; }//end switch I would suggest that you put the different form processing code in different functions so that the case structure doesn't get super cluttered. Then you could just add new functions, and your case structure will look clean switch($_POST['Submit']){//use the value of the submit button to decide what to do case "form1": process_form1($_POST); break; case "form2": process_form2($_POST); break; default echo "OH GOD THINGS ARE TERRIBLE"; break; } Quote Link to comment https://forums.phpfreaks.com/topic/182858-editing-information/#findComment-965204 Share on other sites More sharing options...
Xtremer360 Posted November 25, 2009 Author Share Posted November 25, 2009 Parse error: syntax error, unexpected T_ECHO, expecting ':' or ';' in /home/content/y/a/n/yankeefaninkc/html/defiant/backstage/backstage_libs/division.php on line 10 <?php { switch($_POST['Submit']){//use the value of the submit button to decide what to do case "form1": //form1 code break; case "form2": //form2 code break; default echo '<h1 class=backstage>Division Management</h1><br />'; echo '<h2 class=backstage>Divisions :: <a href="#">Add New</a></h2><br />'; { $query = "SELECT * FROM efed_list_divisions ORDER BY `name`"; $result = mysql_query ( $query ); // Run The Query $rows = mysql_num_rows($result); if ($rows > 0) { print '<table width="100%" class="table1">'; print '<tr class="rowheading">'; print '<td> </td>'; print '<td>Name</td>'; print '</tr>'; // Fetch and print all records. $i = 0; $current_row = 0; while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) { $current_row++; $sClass = 'row2'; if ($i ++ & 1) { $sClass = 'row1'; } printf ( "<tr class=\"%s\">", $sClass ); print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"ajaxpage('editdivision', 'content', '".$row['division']."'); return false;\">Edit</a></td>"; printf ( "<td valign=\"top\">%s</td>", $row [name] ); print '</tr>'; } echo '</table>'; } else { print '<span>There are no divisions.</span><br />'; } print '<br />'; returnmain(); } break; }//end switch ?> Quote Link to comment https://forums.phpfreaks.com/topic/182858-editing-information/#findComment-965221 Share on other sites More sharing options...
Xtremer360 Posted November 25, 2009 Author Share Posted November 25, 2009 Parse error: syntax error, unexpected T_DEFAULT in /home/content/y/a/n/yankeefaninkc/html/defiant/backstage/backstage_libs/division.php on line 22 <?php { switch($_POST['Submit']){//use the value of the submit button to decide what to do case "form1": //form1 code break; case "editdivision": echo'<h1 class="backstage">Division Management</h1><br />'; echo'<h2 class="backstage">Edit Division</h2><br />'; echo'<form name="editdivision" method="post" action="backstage.php" id="editdivision">'; echo'<table width="100%" class="table2">'; echo'<tr>'; echo'<td width="120" class="rowheading" valign="center">Division:</td><td class="row3"><input type="text" name="division" class="fieldtext490" value=""></td>'; echo'</tr>'; echo'</table><br />'; echo'<center>'; echo'<input type="checkbox" name="deletedivision"><span class="table1heading">Delete Division?</span><br /><br />'; echo'<input type="submit" value="Edit Division" class=button name="editdivision"><br /><br />'; echo'<input type="button" value="Return to Divisions List" class="button200"><br /><br />'; returnmain(); } break; default: echo '<h1 class=backstage>Division Management</h1><br />'; echo '<h2 class=backstage>Divisions :: <a href="#">Add New</a></h2><br />'; { $query = "SELECT * FROM efed_list_divisions ORDER BY `name`"; $result = mysql_query ( $query ); // Run The Query $rows = mysql_num_rows($result); if ($rows > 0) { print '<table width="100%" class="table1">'; print '<tr class="rowheading">'; print '<td> </td>'; print '<td>Name</td>'; print '</tr>'; // Fetch and print all records. $i = 0; $current_row = 0; while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) { $current_row++; $sClass = 'row2'; if ($i ++ & 1) { $sClass = 'row1'; } printf ( "<tr class=\"%s\">", $sClass ); print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"ajaxpage('editdivision', 'content', '".$row['division']."'); return false;\">Edit</a></td>"; printf ( "<td valign=\"top\">%s</td>", $row [name] ); print '</tr>'; } echo '</table>'; } else { print '<span>There are no divisions.</span><br />'; } print '<br />'; returnmain(); } break; }//end switch } ?> Quote Link to comment https://forums.phpfreaks.com/topic/182858-editing-information/#findComment-965227 Share on other sites More sharing options...
Xtremer360 Posted November 25, 2009 Author Share Posted November 25, 2009 All issues were fixed however one last thing. I want to know how to link where it says Add New to the case "addivision". <?php { switch($_POST['Submit']){//use the value of the submit button to decide what to do case "adddivision": print '<h1 class=backstage>Division Management</h1><br />'; print '<h2 class=backstage>Add New Division</h2><br />'; print '<form name="adddivision" method="post" action="backstage.php" id="adddivision">'; print '<table width="100%" class="table2">'; print '<tr>'; print '<td width=120 class=rowheading valign=center>Division Name:</td><td class=row3><input type=text name=divisionname class=fieldtext490></td>'; print '</tr>'; print '</table><br />'; print '<input type="submit" value="Save Division" class="button" name="adddivision"></form><br />'; print '<form method=POST><input type=hidden name=action value=division><input type=submit value="Return to Division List" class=button200></form><br />'; print '<h2 class=backstage><form method=POST><input type=hidden name=action value=mainmenu><input type=submit value="Return to Main Menu" class=button200></form></h2>'; break; case "editdivision": print'<h1 class="backstage">Division Management</h1><br />'; print'<h2 class="backstage">Edit Division</h2><br />'; print'<form name="editdivision" method="post" action="backstage.php" id="editdivision">'; print'<table width="100%" class="table2">'; print'<tr>'; print'<td width="120" class="rowheading" valign="center">Division:</td><td class="row3"><input type="text" name="division" class="fieldtext490" value=""></td>'; print'</tr>'; print'</table><br />'; print'<center>'; print'<input type="checkbox" name="deletedivision"><span class="table1heading">Delete Division?</span><br /><br />'; print'<input type="submit" value="Edit Division" class=button name="editdivision"><br /><br />'; print'<input type="button" value="Return to Divisions List" class="button200"><br /><br />'; returnmain(); break; default: print '<h1 class=backstage>Division Management</h1><br />'; print '<h2 class=backstage>Divisions :: <a href="#">Add New</a></h2><br />'; { $query = "SELECT * FROM efed_list_divisions ORDER BY `name`"; $result = mysql_query ( $query ); // Run The Query $rows = mysql_num_rows($result); if ($rows > 0) { print '<table width="100%" class="table1">'; print '<tr class="rowheading">'; print '<td> </td>'; print '<td>Name</td>'; print '</tr>'; // Fetch and print all records. $i = 0; $current_row = 0; while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) { $current_row++; $sClass = 'row2'; if ($i ++ & 1) { $sClass = 'row1'; } printf ( "<tr class=\"%s\">", $sClass ); print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"ajaxpage('editdivision', 'content', '".$row['division']."'); return false;\">Edit</a></td>"; printf ( "<td valign=\"top\">%s</td>", $row [name] ); print '</tr>'; } print '</table>'; } else { print '<span>There are no divisions.</span><br />'; } print '<br />'; returnmain(); } break; }//end switch } ?> Quote Link to comment https://forums.phpfreaks.com/topic/182858-editing-information/#findComment-965245 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.