laughingchaos Posted January 21, 2012 Share Posted January 21, 2012 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 More sharing options...
litebearer Posted January 21, 2012 Share Posted January 21, 2012 it would help to see more of your code Link to comment https://forums.phpfreaks.com/topic/255463-check-database-and-delete/#findComment-1309796 Share on other sites More sharing options...
bian101 Posted January 21, 2012 Share Posted January 21, 2012 Are you using a $_GET or $_POST method for the form action? Link to comment https://forums.phpfreaks.com/topic/255463-check-database-and-delete/#findComment-1309800 Share on other sites More sharing options...
erdem Posted January 21, 2012 Share Posted January 21, 2012 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 https://forums.phpfreaks.com/topic/255463-check-database-and-delete/#findComment-1309801 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.