Jump to content

Quick Form Help


Cetanu

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

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.