Jump to content

[SOLVED] Deleting from the database


joesaddigh

Recommended Posts

I am trying to do a simple delete from a form based on a unique username. The sql query i know works because if i change it with a relevant username instead of the variable it will delete it. The username is being sent in the url but when I try and get it, it does not get populated.

 

This is the form that the username is selected from.

 

 

<?php
require "../connectadmin.php";	
@$username=$_GET['AgentUsername'];
@$firstname=$_GET['AgentFirstname'];
@$surname=$_GET['AgentSurname'];
$queryagent=mysql_query("SELECT AgentUsername, AgentFirstname, AgentSurname FROM agent order by AgentFirstname");

echo '<form action="deleteagentsubmit.php" method="get">';

echo"<br />";
echo"<label>Delete agent";
        echo"<hr />";
        echo"<br />";
    echo"</label>"; 

echo "<select name='Delete Agent'>";	

while($rowagent = mysql_fetch_array($queryagent)) 
{
	echo "<option selected value='$rowagent[AgentUsername]'>$rowagent[AgentUsername]</option>";	
}

echo "</select>";
echo "<label>";
	echo "<br />";
	echo "<br />";	
	echo '<input type="submit" name="submit" value="submit" class="submitbutton" />';
echo "</label>"; 
echo "</form>";	
mysql_close($conn);	
?>

 

 

This is the script that gets run when the submit button is selected.

<?php
//Deleting from the database so needs admin privileges 
require "../connectadmin.php";	

$username = $_GET['AgentUsername']; 
echo $username;

//Delete admin details from admin table
$queryagent = "DELETE FROM agent
			   WHERE AgentUsername = '$username'";

//Perform the query	  
$agentdetails = mysql_query($queryagent, $conn)
	or die("Unable to delete agent details, Please try again"); 

//Redirect user back to admin page form
//header("Location: agent.php");
//mysql_close($conn);
//exit();	
?>

 

Any help would be much appreciated!

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/149618-solved-deleting-from-the-database/
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.