#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    16
    Rep Power
    0

    Php mysql delete query


    MY update Query works fine but my Delete query doesnt respone, and there is no error occured.Do you know what im doing wrong in my code?
    PHP Code:
    <html>
    <head>
    <body>        
    <?php
    //Replace the variable values 
      
    $host "127.0.0.1";
      
    $root "root";
      
    $pass "";
      
    $database "test";
      
     
    //Connects to Mysql or displays  error
    $con mysql_connect($host,$root,$pass) or die(mysql_error());
     
    //"my_db" is the name of the database.
    $db mysql_select_db($database ,$con);

    if (isset (
    $_POST['delete'])){
    $DeleteQuery "DELETE * FROM users Where  username= '$_POST[username]'";

    mysql_query($DeleteQuery,$con);
    };
    $sql "SELECT * FROM users ";
    $data =  mysql_query($sql,$con);

    echo 
    "<table border=5 cellspacing=0 cellpadding=1> 
    <tr>
    <th>id_user </th>
    <th>username </th>
    <th>password</th>
    <th>last_login</th>
    </tr>"
    ;

    while (
    $record mysql_fetch_array($data)) {
    echo 
    "<form action=delete.php method=post>";

    echo
    "<tr>";
    echo 
    "<td>" .$record['id_user'] . " </td>" ;        
    echo 
    "<td>" ."<input type = text name =username value = ".$record['username'] . " </td>" ;
    echo 
    "<td>" ."<input type = password name =password value = ".$record['password'] . " </td>" ;    
    echo 
    "<td>" .$record['last_login'] . " </td>" ;
    echo 
    "<td>""<input type=submit name= Delete value='Delete'" "</td>";
    echo 
    "</form>";

            }
            echo 
    "</table>";
            
    mysql_close($con);
        
        </
    center>
         </
    body>
         </
    html>
    ?>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,464
    Rep Power
    594
    As you can see from the formatter, your quotes are messed up.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    On planet earth
    Posts
    94
    Rep Power
    10
    This is my delete submission, maybe you are missing something


    PHP Code:
    (isset ("Delete" == $_POST['submit'])){ 
    in my html form

    Code:
    input type="submit"
    Just my 0.02c
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    16
    Rep Power
    0
    but I have include it in my php form.
    PHP Code:
    echo "<td>""<input type=submit name=delete value='delete'" "</td>"
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,464
    Rep Power
    594
    The value is case sensitive with respect to $_POST['delete'].
    PHP Code:
    echo "<td><input type=\"submit\" name=\"Delete\" value=\"delete\"</td>"
    I've also simplified your echo a little for you and added the extra quotes without which some browsers might choke.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    On planet earth
    Posts
    94
    Rep Power
    10
    Originally Posted by johnadamos
    but I have include it in my php form.
    PHP Code:
    echo "<td>""<input type=submit name=delete value='delete'" "</td>"
    I see, you've done it with the echo statement
    Something I wouldn't do it like

  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    16
    Rep Power
    0
    I didnt change anything and it works!!!!!!! lool
    anyway thx
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    16
    Rep Power
    0
    Something else, if this was an update query where I should have use md5 , in order to send the password with hash form into the database?

    e.g.
    PHP Code:
    $UpdateQuery "UPDATE users SET username= '$_POST[username]', password= '$_POST[password]' WHERE username='$_POST[hidden]'"
    and this is the echo
    PHP Code:
    echo "<td>" ."<input type = password name =password value =" .$record['password'] . " </td>" 
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,464
    Rep Power
    594
    1) Please edit your post and resume using [ PHP ] tags.
    2) Stop using the deprecated MySQL extensions and switch to PDO.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo