joesaddigh Posted March 16, 2009 Share Posted March 16, 2009 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 More sharing options...
suma237 Posted March 16, 2009 Share Posted March 16, 2009 Use post method . On the next page accept the agent name using $_POST['Delete_Agent'].ie the name used in the <select name='Delete_Agent'> option. Link to comment https://forums.phpfreaks.com/topic/149618-solved-deleting-from-the-database/#findComment-785708 Share on other sites More sharing options...
joesaddigh Posted March 16, 2009 Author Share Posted March 16, 2009 Thanks that works!! Link to comment https://forums.phpfreaks.com/topic/149618-solved-deleting-from-the-database/#findComment-785713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.