SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Evangelist safeasfcuk's Avatar
    Join Date
    Jan 2006
    Location
    UK (SWANSEA)
    Posts
    517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    updating data in mysql

    im trying to make a script that will update and edit my mysql data i ran into prob with submiting it to the database.

    any one got any ideas??

    thats the code that submites to the database
    Code:
    <?
    include ("dbconnect.php"); 
    
    $avatar=$_POST['avatar'];
    $tutorial=$_POST['tutorial'];
    $title=$_POST['title'];
    
    
    $sql="UPDATE tutorials SET avatar='$avatar', title='$title', tutorial='$tutorial' WHERE ID='$id'";
    $result=mysql_query($sql);
    
    if($result){
    echo "Successful";
    echo "<BR>";
    echo "<a href='list_records.php'>View result</a>";
    }
    else {
    echo "ERROR";
    
    
    }
    ?>

    this code is where i edit the data press submit and it displays an error

    Code:
    <?php
    include ("dbconnect.php"); 
    
    $sql="SELECT * FROM tutorials WHERE id='$id'";
    $result=mysql_query($sql);
    
    $rows=mysql_fetch_array($result);
    ?>
    <table width="400" border="0" cellspacing="1" cellpadding="0">
    <tr>
    <form name="form1" method="post" action="update_ac.php">
    <td>
    <table width="100%" border="0" cellspacing="1" cellpadding="0">
    <tr>
    <td width="2%">&nbsp;</td>
    <td colspan="4">Edit Tutorials</td>
    </tr>
    <tr>
    <td align="center">&nbsp;</td>
    <td colspan="2" align="center">&nbsp;</td>
    <td width="16%" align="center">&nbsp;</td>
    </tr>
    <tr>
    <td align="center">&nbsp;</td>
    <td colspan="2" align="left"><strong>Avator</strong></td>
    <td align="left"><strong>Title</strong></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td width="51%" align="left"><input name="avatar" type="text" id="avatar" value="<? echo $rows['avatar']; ?>"></td>
    <td width="31%" align="left"> <input name="id" type="text" id="frmid" value="<? echo $rows['ID']; ?>" size="5"> </td>
    <td align="left"><input name="title" type="text" id="title" value="<? echo $rows['title']; ?>" size="15"></td>
    </tr>
    <tr>
    <td colspan="3"><textarea name="tutorial" cols="80" rows="50" id="tutorial" value="<? echo $rows['message']; ?>"></textarea></td>
    </tr>
    
    <tr>
    <td>&nbsp;</td>
    <td colspan="2"><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>"></td>
    <td align="center"><input type="submit" name="Submit" value="Submit"></td>
    </tr>
    </table>
    </td>
    </form>
    </tr>
    </table>
    <?
    mysql_close();
    ?>
    any 1 help pls??

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't you also need $id = $_POST['id']; otherwise $id is never set?

  3. #3
    SitePoint Evangelist safeasfcuk's Avatar
    Join Date
    Jan 2006
    Location
    UK (SWANSEA)
    Posts
    517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yea i tryed that but still no joy its strange

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2005
    Location
    Nashville, TN
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try to echo your post results with print_r() to verify values

  5. #5
    I Never Give Up roosevelt's Avatar
    Join Date
    May 2005
    Posts
    515
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post

    Try replacing your $SQL with this one:

    PHP Code:
    $sql="UPDATE tutorials SET avatar = '".$avatar."', 
                               title = '"
    .$title."', 
                               tutorial = '"
    .$tutorial."' 
                               WHERE id = '"
    .$id."'"
    And make sure you have $id = $_POST['id'] set.

  6. #6
    SitePoint Evangelist safeasfcuk's Avatar
    Join Date
    Jan 2006
    Location
    UK (SWANSEA)
    Posts
    517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just did a simple echo "$id and $title and $avatar and $tutorial and everthing was displayed except the id??? i cant figure out why the id isnt set?

    ahh i got ID in the database as capatals which id would i need in caps??

  7. #7
    I Never Give Up roosevelt's Avatar
    Join Date
    May 2005
    Posts
    515
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    In your SQL Query I see WHERE ID = '$id';. But when you are fetching the data it says SELECT * FROM tutorials WHERE id='$id'. The column name (id) should be same not different.

  8. #8
    SitePoint Evangelist safeasfcuk's Avatar
    Join Date
    Jan 2006
    Location
    UK (SWANSEA)
    Posts
    517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok the scipt fetches data with no probs but wont edit it so i changed the ID to id and still no joy?


    im confused lol

  9. #9
    I Never Give Up roosevelt's Avatar
    Join Date
    May 2005
    Posts
    515
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    What error do you exactly get?

  10. #10
    SitePoint Evangelist safeasfcuk's Avatar
    Join Date
    Jan 2006
    Location
    UK (SWANSEA)
    Posts
    517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its just ERROR my error message set in else statment

  11. #11
    I Never Give Up roosevelt's Avatar
    Join Date
    May 2005
    Posts
    515
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    also echo mysql_error();

  12. #12
    SitePoint Evangelist safeasfcuk's Avatar
    Join Date
    Jan 2006
    Location
    UK (SWANSEA)
    Posts
    517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unknown column 'tutorial' in 'field list'

    hmm i cant see a typo?? can you??

  13. #13
    I Never Give Up roosevelt's Avatar
    Join Date
    May 2005
    Posts
    515
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If I am not mistaking your QUERY will be:

    $sql="UPDATE tutorials SET avatar = '".$avatar."',
    title = '".$title."',
    message = '".$tutorial."'
    WHERE id = '".$id."'";

    Because I see when you are fetching the data there's not column named tutorial, but it does have message. I assume message is the column in which the actual content goes.

  14. #14
    SitePoint Evangelist safeasfcuk's Avatar
    Join Date
    Jan 2006
    Location
    UK (SWANSEA)
    Posts
    517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks m8 that fixed that but now its saying it was was updated fine but when i view the results nothing has changed? any ideas why it isnt changing

  15. #15
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Add some debugging:
    PHP Code:
    $sql="..your query here..";
    echo 
    'DEBUG: '.$sql;
    $result=mysql_query($sql) or die(mysql_error()); 

  16. #16
    SitePoint Evangelist safeasfcuk's Avatar
    Join Date
    Jan 2006
    Location
    UK (SWANSEA)
    Posts
    517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol thanks for the help guys damn long thread in short time! lol

    fixed the id issue to i had id defind twice in the update script lol 14 hours in work then try learning php not good move ;( lol


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
  •