Results 1 to 2 of 2

Thread: rewriting existing information in mysql

  1. #1
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default rewriting existing information in mysql

    Hi, I have sql table named: THEME, and line in it, named: Thh, were i saved Thh variable from form. Can someone explain what Form script do i need to rewrite information in Thh. For example: Thh was badboy, but when i went to my webpage i want to change it to goodboy what script i have to use? MANY THANKS

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    form.html
    Code:
    ...
    <form action="processform.php" method="post">
        <input type="text" name="Thh">
    <!--OR THIS INSTEAD (comment out above <input> and uncomment this to use)
        <select name="Thh">
            <option value="badboy">Bad Boy</option>
            <option value="goodboy">Good Boy</option>
        </select>
    -->
    <!--then submit the form-->
        <input type="submit" value="submit">
    </form>
    ...
    processform.php
    PHP Code:
    if(isset($_POST['Thh'])){
        
    $Thh $_POST['Thh'];
        
    $Thh addslashes($Thh);
        
    $id '';  // id of the row you want to update
        // IMPORTANT!  if you don't specify a row, ALL ROWS will be updated!
        
    $SQL "UPDATE theme SET Thh = '$Thh' WHERE id ='$id' ";
        
    // This assumes you've already connected to your DB
        
    if(mysql_query($SQL)){ echo 'Success!'; }else{ echo 'Failure.'; }

        
    // if you used the <select> on the form you can easily validate the user's input 
        // (comment out the lines above and uncomment these):
        // $OKvalues = array('badboy','goodboy');
        // if(in_array($_POST['Thh'], $OKvalues)){
        //    $Thh = $_POST['Thh'];
        //    $id = ''; // id of the row you want to update
        //    $SQL = "UPDATE theme SET Thh = '$Thh' WHERE id ='$id' ";
        //    if(mysql_query($SQL)){ echo 'Success!'; }else{ echo 'Failure.'; }
        // }


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
  •