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
https://forums.phpfreaks.com/topic/255463-check-database-and-delete/
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."'

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.