Deleting Match Type
Posted: Sat Feb 14, 2009 12:32 pm
I'd like to know how to incorporate and if statement into my form submission code so that if when it goes to the DB and does the UPDATE if it sees that the user has checked the checkbox to delete the user then it goes ahead and deletes it.
Code: Select all
function editmatchtype()
{
$matchtype = $_GET['matchtype'];
$query = mysql_query("SELECT * FROM `matchtypes` WHERE `matchtype` = '" . $matchtype . "'");
$row = mysql_fetch_array($query);
print '<h1 class="backstage">Match Type Management</h1><br />';
print '<h2 class="backstage">Edit Match Type</h2><br />';
print '<table width="100%" class="table2">';
print '<tr>';
print "<td width=\"120\" class=\"rowheading\" valign=\"center\">Type Name:</td><td class=\"row3\"><input type=\"text\" name=\"matchtype\" class=\"fieldtext490\" value=\"".$row['matchtype']."\"></td>";
print '</tr>';
print '</table><br />';
print '<input type="checkbox" name="deletematchtype"><span class="table1heading">Delete Match Type?</span><br /><br />';
print '<input type="submit" value="Edit Match Type" class=button><br /><br />';
print '<input type="button" value="Return to Match Type List" class="button200"><br /><br />';
print '<h2 class=backstage><input type="button" value="Return to Main Menu" class="button200"></form></h2>';
}Code: Select all
//Form was submitted - determine the form
if ( isset ( $_POST['editmatchtype'] ) )
{
// Define the query.
$typename = mysql_real_escape_string($_POST['typename']);
$query = sprintf("UPDATE INTO `matchtypes` (`matchtype`) VALUES ('%s','%s')", $typename);
// Execute the query.
// Good. This error checking method is recommended.
if (@mysql_query ( $query ))
{
print '<p>The match type has been edited.</p>';
} else
{
print '<p>Could not add the entry because: <b>"' . mysql_error() . '"</b>. The query was '.$query.'.</p>';
}
//mysql_close ();
}