Jump to content

update a table logic


poe

Recommended Posts

i have a user edit link page where the link owner can login and view thier links & descriptions.

 

then if the person wants to edit their description, they click a button and it takes them to a 'edit_link' page.

 

when this 'edit_link' page is submitted, it is stored in a 'revised_link' table in my db.

 

i (the admin)then come along and approve the changes before they go live.

 

so. what i have is:

 

edit_link.html:

<form action='edit.php' method=post>
<input type=text name='link_id' value='6'>
<input type=text name='link_owner_id' value='4'>
link : 'http://yadayadayada.com'<br>
description : <input type=text name='link_desc' value='this is georges favorite link'><br>
<input type=submit value=click><br>
</form>

 

edit.php:

<?php

function get_revised_id($sql)
{
$result = mysql_query( $sql );
while($row = mysql_fetch_array($result))
{
	return $row['id'];
}
}


$link_id = $_post['link_id'];
$link_owner_id = $_post['link_owner_id'];
$link_desc = $_post['link_desc'];


// get the original link info
$sql = " SELECT * FROM link WHERE id = $link_id LIMIT 1 ";
$result = mysql_query( $sql );
while($row = mysql_fetch_array($result))
{
$orig_link = array(
	'id' => $row['id'],
	'title' => $row['title'],
	'url' => $row['url'],
	'description' => $row['description'],
	);
}


// check to see if the new link description is equal to the original
// if NOT, then it must be revised 
if($link_desc != $orig_link['description'])
{
$revise_link[] = array(
	'orig_desc' => $orig_link['description'],
	'new_desc' => $link_desc,
	'lid' => $link_id,
	'owner_id' => $link_owner_id,
);
}



$reviseCnt = count($revise_link);
if($reviseCnt > 0)
{


$sql_check = " SELECT id FROM revised WHERE lid = '$revise_link['lid']' LIMIT 1 "

$sql_update = " UPDATE revised SET orig_desc = $revise_link['orig_desc'], new_desc = $revise_link['new_desc'], lid = $revise_link['lid'], owner_id = $revise_link['owner_id'] ";

$rev_id = get_revised_id($sql_check);
$sql_update .= ( $rev_id > 0 ) ? " WHERE id = $rev_id " : "";



$sql_insert = " INSERT INTO revised (orig_desc, new_desc, lid, owner_id) VALUES ( '$revise_link['orig_desc']', '$revise_link['new_desc']', '$revise_link['lid']', '$revise_link['owner_id']' ) ";



// check if link is already in the revised table awaiting approval.
// if so, update else insert new.
$sql_revise = ( mysql_num_rows(mysql_query( $sql_check )) ) ? $sql_update : $sql_insert;


mysql_query( $sql_revise );

}

?>

 

 

here is where i see an issue.

 

if george changes the description of his link from 'this is georges favorite link' to 'george really loves this site' my script will see that a change has been made and therefor insert/update (depending if a prior change is in the revised table) into the revised table.

 

no problem so far... except BEFORE the admin can approve georges new description and update the 'link' table with the new description, george decides that he wants to revert back to his previous description.

 

since george now submits a revsion of 'this is georges favorite link' which is identical to the description that sits in the 'link' table, the script will not update the pending description change in the revised table.

 

so when the admin gets around to approving description changes from the 'revised' table he will inadvertantly accept georges description change of 'george really loves this site' even though george had tried to change back to his original description.

 

any ideas on ho i might go about from preventing this from happening, i guess by reworking my logic...

 

 

thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.