Topic: How Does This Code Work??
Hey, im starting to get really into php but im not completely familiar with all the code yet.
I had my cousin type this up for my login system and its a comment/Guestbook thing.
It works but im really not sure how and i would love to understand whats happening in this code. Could anyone please go through the code and explain whats happening?
The code is below, but here is an example of what im looking for..
$message = htmlspecialchars(addslashes("$_POST[message]"));
**This sets the variable "$message"**
Ideally i would like en explanation like that for every line, thanks so much in advance.
______________________________________________________________________________
//submit comment
switch ($_GET['page'])
{ case 2:
if(isset($_GET["sign"]))
{
$message = htmlspecialchars(addslashes("$_POST[message]"));
$time = date("F j, Y, g:i a");
$querty = mysql_query("INSERT INTO guestbook(owner,postedby,post,time) VALUES('$req_user','$session->username','$message','$time')");echo "<center>Your
message has been posted</center><br>"; }
else {echo ( "Message was not posted" ); // or no request sent
}
break;
}
// Display comment system
$req_user = trim($_GET['user']);
$getcomments = mysql_query( "SELECT * FROM `guestbook` WHERE `owner` = '$req_user' ORDER BY `ID` DESC" );
while ($comments = mysql_fetch_array($getcomments))
{
echo "<a href='userinfo.php?user=$comments[postedby]'>$comments[postedby]</a> ($comments[time]) - $comments[post] <br>";
}
//Display comment submit box
echo "<center><br/><b>Sign $req_user's guestbook</b><br/>
<form action='userinfo.php?page=2&user=$req_user&sign=$req_user&from=".$session->username."/' method='POST'>
<textarea name='message' rows='5' cols='30' align='left'></textarea><br/><input type='submit' value='Update' name='submit'></form></center>";
/* Link back to main */
echo "<br>Back To [<a href=\"main.php\">Main</a>]<br>";
?>
This is the line i really dont get,
<form action='userinfo.php?page=2&user=$req_user&sign=$req_user&from=".$session->username."/' method='POST'>
What page is that? i have a userinfo.php but what all the ?page= stuff.. i know its a HUGE part of php but i'm really new to this..
Last edited by delirium (2009-11-04 22:39:50)
