Results 1 to 2 of 2

Thread: Stuck with PHP & MySQL update function

  1. #1
    Join Date
    Jul 2009
    Location
    Lithuania
    Posts
    25
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Question Stuck with PHP & MySQL update function

    I tried lot functions of internet, however it doesn't works, and I can't find out where is mistake :S
    This is my edit.php:
    PHP Code:
    <?
    ////////////////////////////////////////////////////////
    //             Prisegame MySQL nustatymus                //
    ////////////////////////////////////////////////////////
        
    include('_include/dbsettings.php');
        
    /////// Jungiames prie MySQL ir pasirenkame lentele
        
    mysql_connect(host,user,pass) or die(mysql_error());
        
    mysql_select_db(db_table);
    $id $_GET["id"];
    $sql "SELECT * FROM naujienos WHERE id=$id";
    $result mysql_query($sql);        
     
    $i=0;

    $id=mysql_result($result,$i,"id");
    $tema=mysql_result($result,$i,"tema");
    $naujiena=mysql_result($result,$i,"naujienos");
     
    echo 
    "<form action=\"update.php\" method=\"post\">
    <span style='visibility:hidden;'><input type='text' name='id' value="
    .$id." /></span>
    Tema: <input name='tema' type=\"text\" size=\"9\" value="
    .$tema."> <br />
    Naujiena: <textarea name='naujiena'>"
    .$naujiena."</textarea>
    <input type=\"submit\" value=\"Save Changes\">
    </form>"
    ;
     
    mysql_close();
    ?>
    It's working perfectly, however.. If I write a new information and post it into my this update.php:
    PHP Code:
    <?
    ////////////////////////////////////////////////////////
    //             Prisegame MySQL nustatymus                //
    ////////////////////////////////////////////////////////
        
        
    include('_include/dbsettings.php');
        
    /////// Jungiames prie MySQL ir pasirenkame lentele
        
    mysql_connect(host,user,pass) or die(mysql_error());
        
    mysql_select_db(db_table);
        
        
    $ud_id=$_POST['id'];
        
    $ud_tema=$_POST['tema'];
        
    $ud_naujiena=$_POST['naujiena'];

        
    $query="UPDATE naujienos SET tema='$tema', naujienos='$naujiena' WHERE id='$id'";
        
    mysql_query($query);
        echo 
    "Record Updated";
        
    mysql_close();
        
    ?>
    It's not updating the row I need. Actually it's only shows that record updated however it's not.

    Any ideas?

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    You dont have $tema, $naujiena or $id set in your sql update you have them called $ud_id, $ud_tema, and $ud_naujiena.
    Corrections to my coding/thoughts welcome.

  3. The Following User Says Thank You to bluewalrus For This Useful Post:

    Total_me (05-08-2010)

Bookmarks

Posting Permissions

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