Help needed with Sessions and Array stuff.
Posted: Fri Mar 20, 2009 11:38 am
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Hi there,
I'm fairly new to PHP and I am trying to make a simple blog, that allows me to edit posts that have been made.
Currently I have managed to make it so that when I click edit of a certain post it sends the first entry from my database to the edit.php page. How can I send the correct message to the edit.php page?
I have done some research into multidimensional arrays, but was unsure if this was the right direction to go in, and after trying to get my head around them I figured I'd ask for help.
blog.php
edit.php:
Any help would be greatly appreciated!
Cheers
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Hi there,
I'm fairly new to PHP and I am trying to make a simple blog, that allows me to edit posts that have been made.
Currently I have managed to make it so that when I click edit of a certain post it sends the first entry from my database to the edit.php page. How can I send the correct message to the edit.php page?
I have done some research into multidimensional arrays, but was unsure if this was the right direction to go in, and after trying to get my head around them I figured I'd ask for help.
blog.php
Code: Select all
<?php
include("wdc.php");
$query="SELECT * FROM `blog` ORDER BY `date` DESC";
$result=mysql_query ($query)
or die("SQL failed");
if(mysql_num_rows($result)==0)
{
echo"There are no messages";
echo"<p><a href='index.php'>Click here</a> to go home.</p>";
}
else
{
while ($row=mysql_fetch_array($result))
{
echo "<table class='blogtable'><tr><td class='blogdate' colspan='2'>Date: ".$row["date"]."</td></tr>";
echo "<tr><td class='bloguser'><font color='".$row["color"]."'><b>".$row["username"]."</b></font></td>";
echo "<td class='blogmessage'>".nl2br($row["message"])."<br/><br /><a href='edit.php'>[edit]</a></td></tr>";
echo "</table>";
$m = $row["message"];
$_SESSION["edit"] = $m;
}
}
mysql_close($conn);
?>edit.php:
Code: Select all
<?php
if ( !isset ($_SESSION["gatekeeper"]))
{
echo "You're not logged in. Go away!";
}
else
{
echo "Hi " .$a.", please edit your message and click 'Update Message'." ;
echo "<form action='updateblog.php' method='POST'>";
echo "<table class='messagetable'>";
echo "<tr>";
echo "<td width='157'>Message:</td>";
echo "</tr>";
echo "<tr>";
echo "<td width='157'><textarea class='textarea' name='blogmessage'>".$m."</textarea></td>";
echo "</tr>";
echo "<tr>";
echo "<td><input type='submit' value='Update Message' /></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
echo" <a href='blog.php'>View Blog</a>";
}
?>Cheers
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: