Jump to content

check database and delete


laughingchaos

Recommended Posts

Hello

i have a text box and a button on my webpage and want to get the text box to find the username i type into it from the database and when it does it will then go to number and delete any text that is under usernames number field as you can see i have no idea how.

 

$result = mysql_query("DELETE FROM mytable WHERE username='$username1' AND number='$number1'" );

 

<form name="form1" method="post" action="p.php">
<p><input type="submit" value="Enter" /></p>
<input name="username" type="text" id="username" size="15" maxlength="35" value="<?php echo $username1; ?>" />
</form>

Link to comment
Share on other sites

form.php

 

<form name="form1" method="post" action="p.php">
<p><input type="submit" value="Enter" /></p>
<input name="username" type="text" id="username" size="15" maxlength="35" value="<?php echo $username1; ?>" />
</form>

 

p.php

 


<?php

// take the username from the form.
$Username = mysql_real_escape_string($_POST['username']);


//check if is form sent empty
if(!empty($Username)){
    // if is not check database if there username tehere
    $sql = mysql_query("SELECT * FROM users WHERE username='".$Username."'")or mysql_error();
    
    if(mysql_num_rows($sql)){
       //if its there delete it
          $delete = mysql_query("DELETE from users WHERE username='".$Username."'")or mysql_error();

          echo "Deleted";
    }else{
          echo "I can't find the username - ". $Username;
   }
}else{

    echo "Form was empty";
}

?>

 

if you want to check the number just put this

 

AND number = '".$Number."'

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.