Form not submitting to database
Posted: Mon Dec 07, 2009 3:24 am
I simply have a form that is loaded through ajax and is not running its insert tag with the values of the fields to the database. I was told its because I HAVE TO do something else to the data before it can be put through to the database but I don't know what it is. When the page is loaded (default is option 0) the user must select Add New (option 1) to go to the add new division form. Currently after a test run of the form is ran it goes to the backstage.php file seeing as how that's in the form action currently. Just saying that its all that the script does after the user clicks submit.
Code: Select all
<?php
{
print "<script src=\"/jscripts/scriptaculous/prototype.js\" type=\"text/javascript\"></script>\n";
print "<script src=\"/jscripts/scriptaculous/scriptaculous.js\" type=\"text/javascript\"></script>\n";
print "<script type=\"text/javascript\" src=\"./jscripts/ajax.js\"></script>\n";
}
?>
<?php
$option = $_GET['option'];
if ($option == 0 )
{
print '<h1 class=backstage>Division Management</h1><br />';
print "<h2 class=\"backstage\">Divisions :: <a href=\"#\" onclick=\"ajaxpage('backstage_libs/division.php?option=1', 'content'); return false;\">Add New</a></h2><br />";
$query = "SELECT * FROM efed_list_divisions";
$result = mysql_query ( $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>';
$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('backstage_libs/division.php?option=2', 'content'); 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();
} elseif ( $option == 1)
{
include('../backstageconfig.php');
include('../backstagefunctions.php');
print '<h1 class="backstage">Division Management</h1><br />';
print '<h2 class="backstage">Add New Division</h2><br />';
print '<form name="submit" method="post" action="backstage.php">';
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="name" class="fieldtext490"></td>';
print '</tr>';
print '</table><br />';
print '<input type="submit" value="Save Division" class="button" name="submit" onclick="division()"></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 />';
returnmain();
} elseif ( $option == 2)
{
include('../backstageconfig.php');
include('../backstagefunctions.php');
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();
}
?>
<?php
{
function division()
{
if(isset($_POST['adddivision']))
{
$name = $_POST['name'];
$query = "INSERT INTO `efed_list_divisions` (`name`) VALUES ('$name')";
if (@mysql_query ($query))
{
print '<p>The division has been added.</p>';
} else
{
print '<p>Could not add the entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>';
}
}
}
}
?>