Jump to content

Recommended Posts

I think I completely massacred this form, but you know, I'm learning. I just want it to delete a user's account after they check yes or no...

 

<fieldset style="padding: 10px;">
<legend>Delete Account: <?php echo "{$_SESSION['username']}"; ?></legend> 
<form action="daccount.php" method="get"> 
<input type="radio" name="yes" value="Delete Account"/>Yes<br/>
<input type="radio" name="no" value="No"/>No<br/>
<input type="submit" value="Submit" name="Submit"/>
</form>
</fieldset> 
<?php 
include "db.php";
if($_GET['Delete Account'] && $_GET['Submit']){
  $sql = "DELETE FROM users WHERE `id`={$_GET['id']} AND `username`={$_SESSION['username']}"; 

$query = mysql_query($sql) or die(mysql_error());
echo " Hope you enjoyed MythScape. Sorry you un-registered.";
echo "<a href=\"index.php\"> Click here </a> to Go Home";
}
else{
echo "Not deleted!"; 
}
?>

 

What it's doing is:

 

-Allowing me to highlight yes AND no...

-Echoing "Not Deleted" before anything is checked or submitted.

-Not deleting the account.

Link to comment
https://forums.phpfreaks.com/topic/166311-quick-form-help/
Share on other sites

<?php 
include "db.php";
if($_POST['yes']=="Delete Account" ){

mysql_query("DELETE FROM users WHERE id='$_POST[id]' AND username='$_SESSION[username]' ");
echo " Hope you enjoyed MythScape. Sorry you un-registered.";
echo "<a href=\"index.php\"> Click here </a> to Go Home";
}
else{
echo "Not deleted!"; 
}
?>

but you need to add the id as a hidden input to the form

 

<input type="hidden" name="id" value="theidhere"/>

Link to comment
https://forums.phpfreaks.com/topic/166311-quick-form-help/#findComment-877014
Share on other sites

<?php
$id = how ever you get you id ;
echo "
<fieldset style='padding: 10px;'>
<legend>Delete Account: " . $_SESSION['username'] . "</legend>
<form action='daccount.php' method='get'> 
<input type='radio' name='yes' value='Delete Account'/>Yes<br/>
<input type='radio' name='no' value='No'/>No<br/>
<input type='hidden' name='id' value='$userid'/>
<input type='submit' value='Submit' name='Submit'/>
</form>
</fieldset> ";

include "db.php";
if($_POST['yes']=="Delete Account" ){

mysql_query("DELETE FROM users WHERE id='$_POST[id]' AND username='$_SESSION[username]' ");
echo " Hope you enjoyed MythScape. Sorry you un-registered.";
echo "<a href=\"index.php\"> Click here </a> to Go Home";
}
else{
echo "Not deleted!"; 
}
?>

Link to comment
https://forums.phpfreaks.com/topic/166311-quick-form-help/#findComment-877018
Share on other sites

opp and this

<?php
$id = how ever you get you id ;
echo "
<fieldset style='padding: 10px;'>
<legend>Delete Account: " . $_SESSION['username'] . "</legend>
<form action='daccount.php' method='POST'> 
<input type='radio' name='yes' value='Delete Account'/>Yes<br/>
<input type='radio' name='no' value='No'/>No<br/>
<input type='hidden' name='id' value='$userid'/>
<input type='submit' value='Submit' name='Submit'/>
</form>
</fieldset> ";

include "db.php";
if($_POST['yes']=="Delete Account" ){

mysql_query("DELETE FROM users WHERE id='$_POST[id]' AND username='$_SESSION[username]' ");
echo " Hope you enjoyed MythScape. Sorry you un-registered.";
echo "<a href=\"index.php\"> Click here </a> to Go Home";
}
else{
echo "Not deleted!"; 
}
?>

Link to comment
https://forums.phpfreaks.com/topic/166311-quick-form-help/#findComment-877049
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.