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 5 of 5

Thread: Update?

  1. #1
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts

    Update?

    I've gone through it 100 times and I can't seem to find the error, and I've worked with php for a very long time, I'm sure anyone can find the error in my sick state.

    I updated my form and now it will not update...

    if($_POST['edit_submit']) {

    $id = $_POST['id'];
    $type = escape_data( $_POST['type'] );
    $title = escape_data( $_POST['title'] );
    $titlejap = escape_data( $_POST['japtitle'] );
    $image= escape_data( $_POST['image'] );
    $genres = escape_data( $_POST['genres'] );
    $formats = escape_data( $_POST['formats'] );
    $episode_number = escape_data( $_POST['episode_number'] );
    $length = escape_data( $_POST['length'] );
    $year = escape_data( $_POST['year'] );
    $opening = escape_data( $_POST['opening'] );
    $ending = escape_data( $_POST['ending'] );
    $summary = escape_data( $_POST['summary'] );
    $episode = escape_data( $_POST['episode'] );
    $review = escape_data( $_POST['review'] );
    $s_author = escape_data( $_POST['s_author'] );
    $r_author = escape_data( $_POST['r_author'] );
    $last_updated = date("Y-m-d");

    //Check if any fields are empty or not
    if((empty($title)) OR (empty($summary))) {
    echo "<center><b>Please fill in all required fields!</b></center>";

    } else {
    //The MySQL query which will update the content in the table.
    $query = "UPDATE anime_reviews SET title = '$title', title_jap = '$titlejap', image = '$image', genres = '$genres', formats = '$formats', episode_number = '$episode_number', length = '$length', released = '$year', opening_t = '$opening', ending_t = '$ending', summary = '$summary', review = '$review', s_author = '$s_author', r_author = '$r_author', episodes = '$episode', last_updated = '$last_updated', type = '$type' WHERE id = '$id'";
    //Execute the query.
    $result = mysql_query($query) or die(mysql_error());
    echo '<meta http-equiv="Refresh" content="10; URL=/" />The entry has been edited, please wait a few seconds (3) while I redirect you.<br> if not then click <a href="/">here!</a>';

    }

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,493
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    how about this ... at the very end ...

    //Execute the query.
    $result = mysql_query($query) or die(mysql_error());
    echo '<meta http-equiv="Refresh" content="10; URL=/" />The entry has been edited, please wait a few seconds (3) while I redirect you.<br> if not then click <a href="/">here!</a>';

    }
    }

  • #3
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Sorry, I didn't want to include my WHOLE code but that wasn't the problem:

    This is what's underneath the given code:
    PHP Code:
    } elseif($_GET['id']) { 
    After this is the form and so on and so on...

    I've partially tested it by placing an echo before the MySQL Query so the form is work perfectly I think.

  • #4
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Oh, I found the problem, it was my form I was missing a tag to declare the id

    <input type="hidden" name="id" value="<?php echo "$id"; ?>" />

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    You need to use intval() or similar on $_POST['id'];
    PHP Code:
    $id intval($_POST['id']); 


  •  

    Posting Permissions

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