Results 1 to 11 of 11
  1. #1
    Join Date
    May 2004
    Location
    Milton, Florida
    Posts
    783

    PHP // MYSQL Problem.. Please Help.

    Im not sure exactyl whats wrong (It doesnt give me a Error Message).. But when I run the script and choose to edit a blog it doesnt show up as being editted... I have tried to trouble shoot this already and cant seem to find out why it wont update the table..

    I Know the mySQL statement/query is a valid query b/c I have echo'd what it gave me and input that into phpmyadmin myself (and it worked).. But something in my script is stoping it.. If anyone can help it is greatly appreciated...

    PHP Code:
    <?php
    mysql_connect
    ($host,$user,$pass); 
                    @
    mysql_select_db($database) or die( "Unable to select database"); 
                     
    $area $_GET['area']; 
                     
    $u=$cookieinfo
                    switch(
    $area) { 
                    case 
    blog
                    
    $GETx mysql_query("SELECT * FROM `blog` WHERE blog_author='$u'") or
    die(
    mysql_error()); 
                    
    $x mysql_num_rows($GETx); 
                    
    $result mysql_query("SELECT * FROM `blog` WHERE blog_author='$u' ORDER
    BY blog_id DESC"
    ) or die(mysql_error()); 
                        if(
    $x!=0) { 
                        
    $FontColor "#f7f7f7"
                        
    $ShowBlog .="<table width='100%' border='0' cellspacing='0'
    cellpadding='0' bgcolor='F2F8FA' style='border: 1px solid #C1D4EC;
    font-size: 12px; color: #"
    .$FontColor.";'> 
                   <tr> 
                     <td align='left' width='100px'>Actions</td> 
                     <td align='left' width='380px'>Title</td> 
                   </tr></table>"

                            for(
    $i=0$i $x$i++) { 
                                  
    $row mysql_fetch_assoc($result); 
                                
    $author $row['blog_author']; 
                                
    $title $row['blog_title']; 
                                
    $blog_id $row['blog_id']; 
                                
    $ShowBlog .="<table width='100%' border='0' cellspacing='0'
    cellpadding='0' bgcolor='F2F8FA' style='border: 1px solid #C1D4EC;
    font-size: 12px; color: #"
    .$FontColor.";'> 
                                <tr> 
                     <td align='left' width='100px'><a
    href='http://www.rateage.com/go2.php?go=user2php&area=blog&action=edit&blogID=$
    blog_id'>Edit</a> :: <a
    href='http://www.rateage.com/go2.php?go=user2php&area=blog&action=delete&blogID
    =
    $blog_id'>Delete</a></td> 
                     <td align='left' width='380px'><a
    href='http://www.rateage.com/profile.php?u=
    $author&blog_id=$blog_id'>$title</a
    ></td> 
                   </tr></table>"

                 } 
                 } 
                    echo 
    $ShowBlog
                        if(isset(
    $_GET['action']) && isset($_GET['blogID'])) { 
                            
    $blogID $_GET['blogID']; 
                            
    $action $_GET['action']; 
                            switch(
    $action) { 
                                case 
    edit
                                echo 
    "<br>"
                                
    $Eresult mysql_query("SELECT * FROM `blog` WHERE
    blog_id='
    $blogID'") or die(mysql_error()); 
                                
    $Erow mysql_fetch_assoc($Eresult); 
                                
    $title=$Erow['blog_title']; 
                                
    $body=$Erow['blog_body']; 
                                
    $blog_id=$Erow['blog_id']; 
                                
    $ShowEditForm .="<form name='editBlog' method='post'
    action='http://www.rateage.com/go2.php?go=user2php&area=blog&action=edit&blogID
    =
    $blog_id&do=edit'> 
    <input type='hidden' name='blog_id' value='
    $blod_id'> 
    <table width='480px' border='0' cellspacing='0' cellpadding='0'
    bgcolor='F2F8FA' style='border: 1px solid #C1D4EC; font-size: 12px; color:
    #'.
    $FontColor.';'> 
                   <tr> 
                     <td width='55PX'>TITLE:</td> 
                     <td><input name='title' type='text' id='title'
    value='
    $title' size='45' maxlength='255'></td> 
                   </tr> 
                   <tr> 
                     <td>BODY:</td> 
                     <td><textarea name='body' cols='40'
    rows='5'>
    $body</textarea></td> 
                   </tr> 
                   <tr> 
                     <td>&nbsp;</td> 
                     <td><input type='submit' name='Submit'
    value='Submit'></td> 
                   </tr> 
                 </table> 
                 </form>"

                if(isset(
    $_GET['do'])){ 
                    
    $body=$_POST['body']; 
                    
    $title=$_POST['title']; 
                    
    $blog_id=$_GET['blogID']; 
                    
    $DOresult mysql_query("UPDATE `blog` SET `blog_title` =  '$title',
    `blog_body` = '
    $body' WHERE `blog_id` = '$blog_id'") or
    die(
    mysql_error()); 
                    echo 
    $DOresult
                    
    $ShowEditForm .="Blog Successfully Modifed<br>"
                } 
                echo 
    $ShowEditForm
                                break; 
                                case 
    delete
                                echo 
    "DELETE!!!"
                                break; 
                                default: 
                                echo 
    "ADD!!!"
                            } 
                        } 
                     
                    break; 
                    case 
    profile
                    echo 
    "PROFILE!!!"
                    break; 
                    case 
    pm
                    echo 
    "PRIVATE MESSAGES!!!"
                    break; 
                    default: 
                    echo 
    "IMAGES!!!"
                    break; 
                    } 
                    
    mysql_close();
    ?>
    Thanks Again.
    Robert

  2. #2
    Join Date
    Jun 2003
    Location
    USA
    Posts
    27
    Your edit form is submitting a blank blog_id. Accidentally placed $blod_id instead of $blog_id (where you first instantiate $showEditForm). I didn't look very much farther, but that may be the reason why. Hope it helps; if not it's at least a step closer.
    Brad Liang
    please check out LifeType

  3. #3
    Join Date
    May 2004
    Location
    Milton, Florida
    Posts
    783
    doesnt work =\

    I changed the code a little to echo the query..

    Code:
    $sql ="UPDATE `blog` SET `blog_title` =  '$title', `blog_body` = '$body' WHERE `blog_id` = '$blog_id'";
    mysql_query($sql) or die(mysql_error());
    echo $sql;
    UPDATE `blog` SET `blog_title` = 'asdasda', `blog_body` = 'adasdasda' WHERE `blog_id` = '1'
    ** EDIT **
    I just found this out.. If I click the submit twice it works... but why ?!?
    Last edited by RobertMaltby; 07-20-2005 at 05:05 PM.

  4. #4
    Any chance you can provide an example db so that i can run the script myself and test it to see if i can see the problem..

    The way i tend to fix stuff like this is a little crude, i basically put lots of echos in and rem out all the lines and start one at a time.
    Note to self: Add something funny!
    Search is your friend!

  5. #5
    Join Date
    May 2004
    Location
    Milton, Florida
    Posts
    783
    I just figured it out... Its working.. (I just need to find a way to refresh the whole page after the edit..) so it shows the edit.. Thanks

  6. #6
    Join Date
    May 2004
    Location
    Milton, Florida
    Posts
    783
    WTF!! It doesnt work now.. Same problem again?!?

  7. #7
    Maybe its returning blank data at some point ans messing up?
    Note to self: Add something funny!
    Search is your friend!

  8. #8
    Join Date
    May 2004
    Location
    Milton, Florida
    Posts
    783
    thats not it... Im echo'ing the data everytime i do something new.. =\

  9. #9
    Join Date
    Mar 2004
    Location
    Kingston, Canada
    Posts
    118
    Originally posted by platinumn23
    thats not it... Im echo'ing the data everytime i do something new.. =\
    The data you are echoing, is it from your input fields or from the database?

    Have you checked in phpMyAdmin to ensure that the data is going into the database? Just because you are echoing a correct query does not mean the data is doing into the database.
    Last edited by fozzy; 07-21-2005 at 08:40 AM.
    My site: redclaw.ca

  10. #10
    Join Date
    May 2004
    Location
    Milton, Florida
    Posts
    783
    Well, Im echo'ing the info from the db then when i submit the new stuff, I echo the data from the form and I echo the $sql query.. after I run the query, I used: mysql_affected_rows(); and that returns 1 which means it changed 1 row.. but it really didnt?!

    Thanks!

  11. #11
    Join Date
    May 2004
    Location
    Milton, Florida
    Posts
    783
    Well.. After looking over my codes.. I was thinking.. Maybe it really is working but just the page might be refreshing... SO, I made a few more error check methods and fixed it..

    Not quite sure why the page is refreshing causing 2 queries.. But I now have a if(isset($title) && isset($body) && isset($u) { before all my updates and inserts and everything runs smoothly now

    Thanks to all that Helped me

Posting Permissions

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