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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.