Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    update/delete from database problem

    PHP Code:
    <?php
    $ud_id
    $_POST['ud_id'];
    $ud_comments=$_POST['ud_comments'];

    include(
    "cons.php");
    echo 
    "<center><table>";

    if (
    $user) {
    if(
    $result mysql_query('SELECT * FROM '.$user.' '))
    {
    while (
    $row=mysql_fetch_assoc($result)) {   
    echo 
    "<center><table>";
        echo 
    '<form action=" ' $PHP_SELF .' " method="POST">   
     <tr><td>Comments:</td><td><input type="text" name="ud_comments" value="' 
    $row['comments']. '"></td></tr>
    <tr><td> </td><td><input type="submit" name="delete" value="X"> <input type="Submit" name="submit" value="Update"></td></tr>
    </form>'
    ;   
    echo 
    "</table></center><br>";
    }

    if (isset(
    $_POST['submit'])) {   
        
    mysql_query('UPDATE '.$user.' SET  `comments`="' $_POST['ud_comments] . '" WHERE `ud_id`="' . $_POST['ud_id'] .'"') or die (mysql_error());   
        echo 'Record Updated.';   
        echo '<script>window.location="' . $PHP_SELF . '";</script>';  
    }


    if (isset($_POST['delete'])) {   
        mysql_query('DELETE FROM '.$user.' WHERE `id`="'.$_POST['
    ud_id'] .'"') or die (mysql_error());  
        echo '<script>window.location="
    updates.php";</script>';  



    mysql_close(); }}

    else

    echo "
    <center>Must be logged in!</center>";}

    ?>
    whats the problem?

    the submit bit works because i get the "test" message

    when i press delete or update submission buttons it just refreshes the page as desired but the new data is not enter or delete and remains unchanged....

    and i get no errors... its connecting to data properly becasue i can add comments using
    PHP Code:
     $query="INSERT INTO ".$user." VALUES ('','$comments')";  
    mysql_query($query);
    mysql_close(); 
    in another file
    i had it working and didnt and now it doesnt work i dont think i changed anything....

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    you are not passing the "ud_id" in your form so consequently your queries do not know which record to update/delete. you need to pass the "ud_id" either via GET on the URL or via hidden form fields.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •