madcrazy1 Posted September 12, 2007 Share Posted September 12, 2007 I have a script that produces a text field with contents of say row8 based on a user columnid when i edit the row contents and click submit, it produces another columnid example: what user sees after clicking submit in quotes userid300 row8 column id28: "This is the text content of column28 in row8" userid300 row8 column id29: "This is the edited text content of column28 in row8" see the column id29? i dont want it, i want the edited info to appear in column id28 to replace it in other words ((I just want row8id28 edited without creating a new rowid)) this is what i am working with: <u>This is the code that produces a user friendly text box to edit the row</u> $RunThisQuery = "SELECT id, title, comments FROM frm_blog_posts WHERE userid=".$_SESSION['logid']." order by id limit 100"; $results = $connector->query($RunThisQuery); while ($row = $connector->fetchArray($results)){ $Blog1= $row['title']; $Blog1a= $row['comments']; $Blog4= $row['id']; <form method="post" action="getindex.php" > <input type="hidden" name="do" value="posts2"> <td><strong>Title</strong><br><input name="p1a" type="text" id="p1a" value="<? if(isset($Blog1)){print $Blog1;} ?>" style="width:85%"></td></tr><tr> <td><strong>Entry</strong><br><input name="p2a" type="text" id="p2a" value="<? if(isset($Blog1)){print $Blog1a;} ?>" style="width:100%"><br></strong><input type="submit" name="Submit" value="Submit" class="button"></form></td> </tr> <? } ?> <u>This is the function that works on the user submitted data</u> $query_add="INSERT INTO `frm_blog_posts` ( `userid` , `title` , `comments` , `date` , `time` ) VALUES ('".$_SESSION['logid']."', '$p1a', '$p2a', '$today_date', '$today_time')"; $result=mysql_query($query_add); $_REQUEST['page'] = "posts2"; $ErrorMessage = "posts updated successfully"; I tried using: REPLACE INTO and UPDATE `frm_blog_posts` SET But could not get these to work for me. Please help. Thanks Quote Link to comment Share on other sites More sharing options...
liebs19 Posted September 12, 2007 Share Posted September 12, 2007 You need to use UPDATE to edit a row. Make sure to include all fields except the id in the values. Then use the ID as the where clause to make sure you only update that 1 row. Quote Link to comment Share on other sites More sharing options...
madcrazy1 Posted September 12, 2007 Author Share Posted September 12, 2007 i tried that, but it updated all the columns with the same title. i need it to just update one column for the user not all the users columns in that same row i already tried this: ############################################################################################################################################### $query_add="UPDATE `frm_blog_posts` SET title='".$_POST['p1a']."' WHERE `userid` =".$_SESSION['logid']; ##################################################################################################################################### i tried substituting session id with column id also with no luck Quote Link to comment Share on other sites More sharing options...
liebs19 Posted September 12, 2007 Share Posted September 12, 2007 That query looks ok to me. Try to echo out your variables to make sure they contain what you expect. Quote Link to comment Share on other sites More sharing options...
madcrazy1 Posted September 12, 2007 Author Share Posted September 12, 2007 The trouble i am having is when the user submits the form the column id is automatically incremented and not being edited directly, thus giving a somewhat duplicate result. the column id needs to be set as auto inc because there are other users ??? Quote Link to comment Share on other sites More sharing options...
madcrazy1 Posted September 12, 2007 Author Share Posted September 12, 2007 the column id is the primary key id Quote Link to comment Share on other sites More sharing options...
liebs19 Posted September 12, 2007 Share Posted September 12, 2007 The primary key should be used as the WHERE clause because it is guaranteed to be unique. Quote Link to comment Share on other sites More sharing options...
madcrazy1 Posted September 13, 2007 Author Share Posted September 13, 2007 $query_add="UPDATE `frm_blog_posts` SET fOrder='".$_POST['p3a']."' WHERE `id`=". $row['id']." and userid =".$_SESSION['logid']; THIS IS WHAT I DID BEFORE I SAW YOUR LAST POST. can you rewrite this with primary key in the where clause. i am not sure how to do it. i just put $row['id'] in it. Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.