All pastes #256673 Raw Edit

Mine

public php v1 · immutable
#256673 ·published 2006-11-24 14:34 UTC
rendered paste body
function edit(){	global $dbc;	global $databasename;	//Connect and select database	if ($dbc)	{		if (!$databasename)		{			die('<p>Could not select the database</p>');		}	}	else	{		die ('<p>Could not connect to MySQL</p>');	}	if (isset ($_POST['submit'])) //If the form was submitted	{		//Current time/date originally NOW()		$rightnow = date('l dS \of F Y g:i:s A');		//Add slashs to entry to make sure it doesn't mess with the mysql		$entry = nl2br ($_POST['entry']);		$entry = mysql_real_escape_string ($entry);		//Define the query		$query = "UPDATE blog_entries SET title='{$_POST['title']}', entry='$entry', date_updated='$rightnow' WHERE pid={$_POST['id']}";		$r = mysql_query ($query); //Execute the query		//Report on the result			if (mysql_affected_rows() == 1)			{				print '<p>The blog entry has been updated</p>';			}			else			{				print "<p>Could not update the entry because <b>" . mysql_error() . "</b>. The query was $query";			}	}	else //If the update form was not submitted	{		if (isset ($_GET['id'])) //If a post is specified		{			if (is_numeric ($_GET['id'])) //Check if the entry wanted is a number			{				$query = "SELECT * FROM blog_entries WHERE pid={$_GET['id']} LIMIT 1";				if ($r = mysql_query ($query)) //Run the query				{					$row = mysql_fetch_array ($r); //Retrieve the information					//Make the form					$theentry = "";					$theentry = $row['entry'];					$theentry = str_replace("<br />", "\n", $theentry);//Odd bug here, no idea why					print '<center><form action="edit_entry.php" method="post">					<p>Entry title: <br /><input type="text" name="title" size="100" style="maxsize: 100" value="' . $row['title'] . '" /></p>					<p>Entry text: <br /><textarea name="entry" cols="100"  rows="20">' . $theentry . '</textarea></p>					<input type="hidden" name="id" value="' . $_GET['id'] . '" />					<input type="submit" name="submit" value="Update this entry!" class="btn"   onmouseover="this.className=\'btnhov\'" onmouseout="this.className=\'btn\'" />					</form></center>';				}				else //Couldn't get the information				{					print "<p>Could not retrieve the entry.";				}			}		}		else //If there is no id specified, display the posts		{			//Define the query to select the blog entries			$query = 'SELECT * FROM blog_entries ORDER BY date_posted DESC';			if ($r = mysql_query ($query)) //Run the query			{				//Retrieve and print every record				while ($row = mysql_fetch_array ($r))				{					print "<p><b>{$row['title']}</b>  (Posted by 'insert something here')					<a href=\"edit_entry.php?id={$row['pid']}\">Edit</a> <a href=\"delete_entry.php?id={$row['pid']}\">Delete</a>					</p>\n";				}			}			else //Query didn't run			{				die ('Could not retrieve the data');			} //End of Query IF.				mysql_close(); //Close the database connection		}	}}