Jump to content

Delete Match Type


Xtremer360

Recommended Posts

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.

 

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>';
}

 

 

//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 (); 
     
    }   

Link to comment
https://forums.phpfreaks.com/topic/145216-delete-match-type/
Share on other sites

This is what I was told but I don't know how I need to fix my delete query if I'm needing to do by the field called matchtype.

 

//Form was submitted - determine the form 
     if ( isset ( $_POST['deletematchtype'] ) )
{
	$query = sprintf("DELETE FROM `matchtypes` (`matchtype`) VALUES ('%s','%s')", $typename); 
}
else 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 (); 
     
    }   

Link to comment
https://forums.phpfreaks.com/topic/145216-delete-match-type/#findComment-762323
Share on other sites

Updated code again but when I go to the form and check the box then it says this when I hit the submit button:

 

Could not delete the entry because: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''matchtypes' WHERE `matchtype` = '' LIMIT 1' at line 1". The query was DELETE FROM 'matchtypes' WHERE `matchtype` = '' LIMIT 1.

 

//Form was submitted - determine the form 
     if ( isset ( $_POST['deletematchtype'] ) )
{
	$query = "DELETE FROM 'matchtypes' WHERE `matchtype` =  '".mysql_escape_string($matchtype)."' LIMIT 1"; 

	// Execute the query. 
        // Good.  This error checking method is recommended.
        if (@mysql_query ( $query )) 
	{ 
            print '<p>The match type has been deleted.</p>'; 
        } else 
	{ 
            print '<p>Could not delete the entry because: <b>"' . mysql_error() . '"</b>. The query was '.$query.'.</p>'; 
        } 
         
        //mysql_close (); 
}
else 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 (); 
     
    }  

Link to comment
https://forums.phpfreaks.com/topic/145216-delete-match-type/#findComment-762358
Share on other sites

Does this table have an auto incremented column?  For example, an ID field that would update itself by one based on the last row's id.  Yes, that is the correct syntax for updating a table row, but it would be a lot better to update the row by what the id is, mainly because this script will update every single row with that same match type.  If this is what you want to do, then yes, it is correct.

Link to comment
https://forums.phpfreaks.com/topic/145216-delete-match-type/#findComment-763084
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.