Jump to content

[SOLVED] edit row without creating new id


madcrazy1

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/69090-solved-edit-row-without-creating-new-id/
Share on other sites

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

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 ???

$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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.