Jump to content

mysql_query("DELETE"); not deleting!


Foser

Recommended Posts

this is my code :

 

if (isset($_POST['delete'])){
echo "Are you sure you want to delete {$_GET['user']}?<br>";
echo "<form id=\"form1\" name=\"form1\" method=\"post\" action=\"\">
  <label>
  <input type=\"submit\" name=\"yes\" id=\"yes\" value=\"Yes\" />
  </label>
  <label>
  <input type=\"submit\" name=\"no\" id=\"no\" value=\"No\" />
  </label>
</form>"; 
if(isset($_POST['yes'])) {
mysql_query("DELETE FROM user_info WHERE username = '$_GET[user]'");
echo "You have deleted this user. Click <p><a href=\"index.php\">here</a></p> to go back to the admin CP."; exit; }
if(isset($POST['no'])){ 
header("Location: user.php?user={$_GET['user']}"); exit; }}

 

and when i press the yes button it does not execute it. is there something wrong? that inm maybe missing

 

thanks a lot!

Link to comment
Share on other sites

Hi,

 

try this code :

 


if (isset($_POST['yes']) || isset($_POST['no'])){
echo "Are you sure you want to delete {$_GET['user']}?<br>";
echo "<form id=\"form1\" name=\"form1\" method=\"post\" action=\"\">
  <label>
  <input type=\"submit\" name=\"yes\" id=\"yes\" value=\"Yes\" />
  </label>
  <label>
  <input type=\"submit\" name=\"no\" id=\"no\" value=\"No\" />
  </label>
</form>"; 
if(isset($_POST['yes'])) {
mysql_query("DELETE FROM user_info WHERE username = '$_GET[user]'");
echo "You have deleted this user. Click <p><a href=\"index.php\">here</a></p> to go back to the admin CP."; exit; }
if(isset($POST['no'])){ 
header("Location: user.php?user={$_GET['user']}"); exit; }}

Link to comment
Share on other sites

but the thing is. that you need toi press edit before seeing the yes or no option. so the way your doing won't apply to the style im making it.  the way i want it, is press delete than says are you sure then yes or no.

Link to comment
Share on other sites

Change this line:

echo '<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'].'?user='.$_GET['user'];?>">';

 

When the user clicks the"yes" button the rest of the URL is being lost, this will preserve it.

Link to comment
Share on other sites

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\WAMP\www\Projects\LogiPlan\main\admin\user.php on line 14

now i get this error... on the edited line.

Link to comment
Share on other sites

now this is my new script:

 

if (isset($_POST['delete'])){
echo "Are you sure you want to delete {$_GET['user']}?<br>";
echo '<form id="form1" name="form1" method="post" action="<?php echo $_SERVER[php_SELF]."?user".$_GET[user]; ?>
  <label>
  <input type="submit" name="yes" id="yes" value="Yes" />
  </label>
  <label>
  <input type="submit" name="no" id="no" value="No" />
  </label>
</form>'; 

 

but for some reason when i get to the page it shows it direcly, eventhugh i did not the delete from $_post[delete]

 

also when i click on either one this shows up:

 

Forbidden

You don't have permission to access /Projects/LogiPlan/main/admin/< on this server.

 

also this is the url i get on that forbidden page:

http://localhost/Projects/LogiPlan/main/admin/%3C?php%20echo%20$_SERVER[php_SELF].

Link to comment
Share on other sites

Looks like you're running the scripts from your PC instead from a web server - I've never done this as all my code gets tested live.

 

If the script is called "deleteuser.php" edit this line:

echo '<form id="form1" name="form1" method="post" action="deleteuser.php?user='.$_GET[user].'">

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.