how i can edit a particular news post in my view news page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
x
Forum Newbie
Posts: 12
Joined: Wed Jun 08, 2005 11:31 pm

how i can edit a particular news post in my view news page

Post by x »

Code: Select all

<?php



if(isset($_POST["n_submit"]))

{ 

?>

<TABLE class="FORMAT" width="80%">
	<tr><TD class="lhead" width="100%" colspan="2"><a class=white><center> 
		Welcome Administrator/Moderator
		</td></tr></center></a>

	<tr><TD class=light ><center>
		<a class=hsblue>Title : </a><input type="text" name="news_h" size="40" maxlength="40" 
		value="<?php if ($nrow[2]!=NULL){echo $nrow['2'];}?>"/><br></a>
	</td></tr>


	<tr><TD class=light ><center><textarea name="news_b" rows="4" cols="40" wrap><?php if (isset($_POST['news_b'])){echo $_POST['news_b'];} ?></textarea></center> 
		<br><center><input type="submit" name="n_submit" value="Update"/></center>
	</td></tr></TABLE></center>

<?php
			}else{



if ($dbc = @mysql_connect($dbhost, $dbuser, $dbpass)) 
	{//make the connection
	if (!mysql_select_db($dbname)) 
		{//handle error
		my_error_handler (mysql_errno(), 'Could not select the database:' . mysql_error());
		echo '<font color="red">The site is currenty experiencing technical difficulties. We apologize for any inconvenience.</font>';
		include_once ("$path_include . menu.php");
		exit();
		}

	}else{
		my_error_handler (mysql_errno(), 'Could not select the database:' . mysql_error());
			echo '<font color="red">The site is currenty experiencing technical difficulties. We apologize for any inconvenience.</font>';
			include_once ("$path_include . menu.php");
			exit();
		}



echo '<TABLE class="FORMAT" width="100%"><tr><TD class="head" width="100%"><a class=large_white><center><b>FORUM NEWS</b></center></td></tr>';

include_once ("mysql_connect.php");


if($news_result){


while($nrow=mysql_fetch_array($news_result, MYSQL_NUM)){
//display head
$poster_identifier=$nrow['4'];
$npic_query = "SELECT * FROM forum_users WHERE uid=$poster_identifier"; 
			$npic_result = mysql_query($npic_query);
			$npic_row = mysql_fetch_row($npic_result);


echo '<TABLE class="white" border=0 width="600"><tr><TD class="light" width="600" colspan=2 border="0"><a class=hgrey><center>' . '<b>'."$nrow[2]".'</a></b>' . 
'</center></a></TD></tr><tr><td><table><tr><td class="light_blue" width="100"><img src='."$path_avatar"."$npic_row[13]".' width="100%" height="100%"></td></tr><tr><td><a class="sgrey">Posted by:</a><tr><td><center><a class="grey">'.' '."$npic_row[4]".'</a></center></td></tr></td></tr></table></td><TD valign="top" width="500" border="10" class="light_blue" cellpadding="5">'.'<a class="hsgrey">'.'<br>'."$nrow[3]".'</a></td></td><tr><td class="light_blue" width="600" colspan="2"><a class=hssgrey>'."$nrow[1]".'</a>'.
'</td></tr>';
$_SESSION['head'] = $nrow[2];
 
if($user_type==1){
?>
<tr><td>
<form action="<?php 


echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="submit" name="n_submit" value="Edit"/>

</td></tr>
<?php

}
echo '</TABLE><br><br>';

}
}
echo '</table>';
}			
?>
im sorry if this is a very easy problem to most of you but i tried looking at pre made forum in php but i cant still get the logic on how i can capture a particular news post using an edit submit button i added to the while statement while retrieving data from mysql, since this is a while statement if i tried making a variable equal to some data in the database to be the link of the post i will edit, it will be updated to the last shown data, so i cant edit the data's prior to the last shown news. i wonder how this is properly done!! tnx in advance
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

to edit a single record, use the records ID in a link or post you can.

ex:

Code: Select all

while($row = mysql_fetch_assoc($result)){
  echo "<a href=\"modify.php?id=".$row['id']."\">Modify Record #".$row['id']."</a>";
}
then fetch the data for that row on modify.php you should.
User avatar
x
Forum Newbie
Posts: 12
Joined: Wed Jun 08, 2005 11:31 pm

Post by x »

although that would mean i will use a different page and not the same page, ill experiment on it

"problem solved man, thanks for the fast reply and patience"
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

You can also pass a variable "task" which indicates what your codes has to do...

But most people adhere to the KISS (Keep It Simple Stupid) principle and choose to have one script for one functionality. Imho list and edit scripts deserve their own file ;)
Post Reply