<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[KillerSites.com Web Design Forums - How Does This Code Work??]]></title>
	<link rel="self" href="http://www.killersites.com/forums/feed/atom/topic/2417/"/>
	<updated>2009-11-05T17:21:29Z</updated>
	<generator>PunBB</generator>
	<id>http://www.killersites.com/forums/topic/2417/how-does-this-code-work/</id>
		<entry>
			<title type="html"><![CDATA[Re: How Does This Code Work??]]></title>
			<link rel="alternate" href="http://www.killersites.com/forums/post/11932/#p11932"/>
			<content type="html"><![CDATA[<p>Thank you so much, just needed that explenation.</p>]]></content>
			<author>
				<name><![CDATA[delirium]]></name>
				<uri>http://www.killersites.com/forums/user/1819/</uri>
			</author>
			<updated>2009-11-05T17:21:29Z</updated>
			<id>http://www.killersites.com/forums/post/11932/#p11932</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: How Does This Code Work??]]></title>
			<link rel="alternate" href="http://www.killersites.com/forums/post/11899/#p11899"/>
			<content type="html"><![CDATA[<p>Realistically, I probably wouldn&#039;t start learning PHP from such a complicated example as this. You might want to consider taking a look at some of the basic articles on <a href="http://www.tizag.com/phpT/" rel="nofollow">http://www.tizag.com/phpT/</a> or doing a couple of the (free) video tutorials on <a href="http://phpvideotutorials.com/free" rel="nofollow">http://phpvideotutorials.com/free</a> to get a basic understanding of PHP, and then come back to this. It&#039;ll make a lot more sense then.</p>]]></content>
			<author>
				<name><![CDATA[falkencreative]]></name>
				<uri>http://www.killersites.com/forums/user/3/</uri>
			</author>
			<updated>2009-11-05T05:51:27Z</updated>
			<id>http://www.killersites.com/forums/post/11899/#p11899</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: How Does This Code Work??]]></title>
			<link rel="alternate" href="http://www.killersites.com/forums/post/11898/#p11898"/>
			<content type="html"><![CDATA[<p>Some of this is a bit hard to describe, partially because the code you have posted appears to be code snippets, rather than the whole thing. Still, you should be able to get a good idea of what is going on.</p><p>I&#039;ve separated out the code into a couple different chunks that do different things...</p><p>This chunk of code takes the input from a form and saves it in the database:<br /></p><div class="codebox"><pre><code>switch ($_GET[&#039;page&#039;]) //this sets up a switch statement, checking for various options. In this case, it gets the value of the &quot;page&quot; variable from the url (filename.php?page=2). If it is &quot;2&quot; it does the code within the &quot;case 2:&quot; block
{     
    case 2: 

    if(isset($_GET[&quot;sign&quot;])) //checks if &quot;sign&quot; is set in the url, and gets the value using $_GET[] (if &quot;sign&quot; is set in the url, it will look something like this: filename.php?sign=value)
    {
        //sets the message variable to the value of the &quot;message&quot; field in the form. htmlspecialchars() and addslashes() are both functions that are intended to help protect against hacking or invalid inputs
        $message = htmlspecialchars(addslashes(&quot;$_POST[message]&quot;));
        
        //sets the time variable to the current time, in the specified format
        $time = date(&quot;F j, Y, g:i a&quot;);
        
        //this is a mysql query that saves the data captured within the form to the database
        $querty = mysql_query(&quot;INSERT INTO guestbook(owner,postedby,post,time) VALUES(&#039;$req_user&#039;,&#039;$session-&gt;username&#039;,&#039;$message&#039;,&#039;$time&#039;)&quot;);

        //displays a message to the user letting him/her know that the comment has been posted.
        echo &quot;&lt;center&gt;Your message has been posted&lt;/center&gt;&lt;br&gt;&quot;; 
    }
    else
    // if the &quot;sign&quot; variable is not set in the URL, show an error 
    {
        echo ( &quot;Message was not posted&quot; ); // or no request sent
    } 

    // end the switch statement
    break;

}</code></pre></div><p>This chunk of code displays the comments (it appears like this only shows comments of the specified user), getting the information from the database<br /></p><div class="codebox"><pre><code>//sets the req_user variable based on the URL
$req_user = trim($_GET[&#039;user&#039;]);

// this is a mysql query that gets the comments from the database
$getcomments = mysql_query( &quot;SELECT * FROM `guestbook` WHERE `owner` = &#039;$req_user&#039; ORDER BY `ID` DESC&quot; );

// this loops through all of the results, repeating the code within the loop until there are no more results 
while ($comments = mysql_fetch_array($getcomments))
{
    // this displays the comment from the database
    echo &quot;&lt;a href=&#039;userinfo.php?user=$comments[postedby]&#039;&gt;$comments[postedby]&lt;/a&gt; ($comments[time]) - $comments[post] &lt;br&gt;&quot;;
}</code></pre></div><br /><p>This displays a form, allowing users to comment. There really isn&#039;t anything super complicated about this...<br /></p><div class="codebox"><pre><code>//displays header text
echo &quot;&lt;center&gt;&lt;br/&gt;&lt;b&gt;Sign $req_user&#039;s guestbook&lt;/b&gt;&lt;br/&gt;

// sets up a form
&lt;form  action=&#039;userinfo.php?page=2&amp;user=$req_user&amp;sign=$req_user&amp;from=&quot;.$session-&gt;username.&quot;/&#039; method=&#039;POST&#039;&gt;

&lt;textarea name=&#039;message&#039; rows=&#039;5&#039; cols=&#039;30&#039; align=&#039;left&#039;&gt;&lt;/textarea&gt;&lt;br/&gt;&lt;input type=&#039;submit&#039; value=&#039;Update&#039; name=&#039;submit&#039;&gt;&lt;/form&gt;&lt;/center&gt;&quot;;

/* Link back to main */
echo &quot;&lt;br&gt;Back To [&lt;a href=\&quot;main.php\&quot;&gt;Main&lt;/a&gt;]&lt;br&gt;&quot;;</code></pre></div><div class="quotebox"><blockquote><p>This is the line i really dont get,<br />&lt;form&nbsp; action=&#039;userinfo.php?page=2&amp;user=$req_user&amp;sign=$req_user&amp;from=&quot;.$session-&gt;username.&quot;/&#039; method=&#039;POST&#039;&gt;</p></blockquote></div><p>When the form is submitted, it goes to the page that is specified within the action perimeter. In this case, it is the userinfo.php page, setting additional variables (in this case, &quot;page&quot; = 2, &quot;user&quot; = the value of the $req_user variable, &quot;sign&quot; = the value of the $req_user variable, and &quot;from&quot; = the username set within the session object (this is a bit over your head... sorry) are the variables) in the URL that will be used by PHP when processing the form.</p>]]></content>
			<author>
				<name><![CDATA[falkencreative]]></name>
				<uri>http://www.killersites.com/forums/user/3/</uri>
			</author>
			<updated>2009-11-05T05:47:48Z</updated>
			<id>http://www.killersites.com/forums/post/11898/#p11898</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[How Does This Code Work??]]></title>
			<link rel="alternate" href="http://www.killersites.com/forums/post/11888/#p11888"/>
			<content type="html"><![CDATA[<p>Hey, im starting to get really into php but im not completely familiar with all the code yet. </p><p>I had my cousin type this up for my login system and its a comment/Guestbook thing. </p><p>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?</p><p>The code is below, but here is an example of what im looking for..</p><p>$message = htmlspecialchars(addslashes(&quot;$_POST[message]&quot;));<br />**This sets the variable &quot;$message&quot;**</p><p>Ideally i would like en explanation like that for every line, thanks so much in advance.</p><br /><p>______________________________________________________________________________<br />//submit comment</p><p>switch ($_GET[&#039;page&#039;])<br />{&nbsp; &nbsp; &nbsp;case 2:&nbsp; </p><p>if(isset($_GET[&quot;sign&quot;]))<br />{</p><p>$message = htmlspecialchars(addslashes(&quot;$_POST[message]&quot;));<br />$time = date(&quot;F j, Y, g:i a&quot;); <br />$querty = mysql_query(&quot;INSERT INTO guestbook(owner,postedby,post,time) VALUES(&#039;$req_user&#039;,&#039;$session-&gt;username&#039;,&#039;$message&#039;,&#039;$time&#039;)&quot;);echo &quot;&lt;center&gt;Your </p><p>message has been posted&lt;/center&gt;&lt;br&gt;&quot;; }</p><p>else {echo ( &quot;Message was not posted&quot; ); // or no request sent<br />}&nbsp; </p><p>break; </p><p>}</p><p>// Display comment system</p><p>$req_user = trim($_GET[&#039;user&#039;]);<br />$getcomments = mysql_query( &quot;SELECT * FROM `guestbook` WHERE `owner` = &#039;$req_user&#039; ORDER BY `ID` DESC&quot; );</p><p>while ($comments = mysql_fetch_array($getcomments))<br />{<br />&nbsp; &nbsp; echo &quot;&lt;a href=&#039;userinfo.php?user=$comments[postedby]&#039;&gt;$comments[postedby]&lt;/a&gt; ($comments[time]) - $comments[post] &lt;br&gt;&quot;;<br />}</p><p>//Display comment submit box</p><p>echo &quot;&lt;center&gt;&lt;br/&gt;&lt;b&gt;Sign $req_user&#039;s guestbook&lt;/b&gt;&lt;br/&gt;<br />&lt;form&nbsp; action=&#039;userinfo.php?page=2&amp;user=$req_user&amp;sign=$req_user&amp;from=&quot;.$session-&gt;username.&quot;/&#039; method=&#039;POST&#039;&gt;</p><p>&lt;textarea name=&#039;message&#039; rows=&#039;5&#039; cols=&#039;30&#039; align=&#039;left&#039;&gt;&lt;/textarea&gt;&lt;br/&gt;&lt;input type=&#039;submit&#039; value=&#039;Update&#039; name=&#039;submit&#039;&gt;&lt;/form&gt;&lt;/center&gt;&quot;;</p><p>/* Link back to main */<br />echo &quot;&lt;br&gt;Back To [&lt;a href=\&quot;main.php\&quot;&gt;Main&lt;/a&gt;]&lt;br&gt;&quot;;</p><p>?&gt;</p><p>This is the line i really dont get, <br />&lt;form&nbsp; action=&#039;userinfo.php?page=2&amp;user=$req_user&amp;sign=$req_user&amp;from=&quot;.$session-&gt;username.&quot;/&#039; method=&#039;POST&#039;&gt;</p><p>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&#039;m really new to this..</p>]]></content>
			<author>
				<name><![CDATA[delirium]]></name>
				<uri>http://www.killersites.com/forums/user/1819/</uri>
			</author>
			<updated>2009-11-05T03:37:40Z</updated>
			<id>http://www.killersites.com/forums/post/11888/#p11888</id>
		</entry>
</feed>
