<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[PHP Forums - Code]]></title>
	<link rel="self" href="http://phpforums.org/feed-atom-forum3.xml"/>
	<updated>2010-07-25T22:46:03Z</updated>
	<generator>PunBB</generator>
	<id>http://phpforums.org/</id>
		<entry>
			<title type="html"><![CDATA[PHP/MySql Login Verification]]></title>
			<link rel="alternate" href="http://phpforums.org/topic32-phpmysql-login-verification-new-posts.html"/>
			<summary type="html"><![CDATA[<p>Hey guys,&nbsp; I&#039;m a new web developer doing things kinda out of my reach so if I sound stupid I&#039;m sorry.&nbsp; I am trying to create a mysql database with usernames and passwords which php will connect to and verify, then in turn redirect the user accordingly.&nbsp; I found a script that does just that but I have some questions about it.<br />I created the Mysql database as such...<br /></p><div class="codebox"><pre><code>CREATE TABLE tbl_auth_user (
user_id VARCHAR(10) NOT NULL,
user_password CHAR(32) NOT NULL,

PRIMARY KEY (user_id)
);

INSERT INTO tbl_auth_user (user_id, user_password) VALUES (&#039;theadmin&#039;, PASSWORD(&#039;chumbawamba&#039;));
INSERT INTO tbl_auth_user (user_id, user_password) VALUES (&#039;webmaster&#039;, PASSWORD(&#039;webmistress&#039;));


//Now that that is created I looked at the PHP code and this is what I have questions on.

&lt;?php
// we must never forget to start the session
session_start();

$errorMessage = &#039;&#039;;
if (isset($_POST[&#039;txtUserId&#039;]) &amp;&amp; isset($_POST[&#039;txtPassword&#039;])) {
   include &#039;library/config.php&#039;;
   include &#039;library/opendb.php&#039;;

   $userId = $_POST[&#039;txtUserId&#039;];
   $password = $_POST[&#039;txtPassword&#039;];

   // check if the user id and password combination exist in database
   $sql = &quot;SELECT user_id
           FROM tbl_auth_user
           WHERE user_id = &#039;$userId&#039;
                 AND user_password = PASSWORD(&#039;$password&#039;)&quot;;

   $result = mysql_query($sql)
             or die(&#039;Query failed. &#039; . mysql_error());

   if (mysql_num_rows($result) == 1) {
      // the user id and password match,
      // set the session
      $_SESSION[&#039;db_is_logged_in&#039;] = true;

      // after login we move to the main page
      header(&#039;Location: main.php&#039;);
      exit;
   } else {
      $errorMessage = &#039;Sorry, wrong user id / password&#039;;
   }

   include &#039;library/closedb.php&#039;;
}
?&gt;</code></pre></div><p>The part that confuses me is the library directory.&nbsp; Do I actually have to create a library directory and the files called closedb.php and opendb.php or is this some apache built in server feature.&nbsp; If i do need to create the directory... are these files already created?&nbsp; The reason I ask is because in the tutorial he gave no source to these files, so I am wondering if they are a standard web script that can be obtained someplace.</p><p>Thank you for any input you may have in advance,<br />Squeaker2</p>]]></summary>
			<author>
				<name><![CDATA[squeaker2]]></name>
				<uri>http://phpforums.org/user44.html</uri>
			</author>
			<updated>2010-07-25T22:46:03Z</updated>
			<id>http://phpforums.org/topic32-phpmysql-login-verification-new-posts.html</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[date n time]]></title>
			<link rel="alternate" href="http://phpforums.org/topic27-date-n-time-new-posts.html"/>
			<summary type="html"><![CDATA[<p>I know that my question may sound stupid, but I&#039;ll ask anyway...</p><div class="codebox"><pre><code>$username = $_POST[&#039;username&#039;];
$email = $_POST[&#039;email&#039;];
$password = md5($_POST[&#039;password&#039;]);
$password2 = md5($_POST[&#039;password2&#039;]);
$location = $_POST[&#039;location&#039;];
$genre = $_POST[&#039;genre&#039;];
$date =</code></pre></div><p>what should I write to insert date and time in the database and what type should I specify on the database side?</p><p>thanks a lot <img src="http://phpforums.org/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></summary>
			<author>
				<name><![CDATA[talviruusu]]></name>
				<uri>http://phpforums.org/user27.html</uri>
			</author>
			<updated>2010-07-01T22:33:01Z</updated>
			<id>http://phpforums.org/topic27-date-n-time-new-posts.html</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[PHP script to select state]]></title>
			<link rel="alternate" href="http://phpforums.org/topic29-php-script-to-select-state-new-posts.html"/>
			<summary type="html"><![CDATA[<p>I have a database table called contacts with a table in it called addresses. The fields in the addresses table are firstname, lastname, address, city, state, zip, areacode and phonenumber. (The state field is a 2 character text field.) I want to ask the user for a state and then I want to display all the records for that state only. Can anyone help me? </p><p>Thanks, </p><p>Andrew</p>]]></summary>
			<author>
				<name><![CDATA[andrewgrz]]></name>
				<uri>http://phpforums.org/user36.html</uri>
			</author>
			<updated>2010-06-12T03:26:22Z</updated>
			<id>http://phpforums.org/topic29-php-script-to-select-state-new-posts.html</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Comma delimited file]]></title>
			<link rel="alternate" href="http://phpforums.org/topic28-comma-delimited-file-new-posts.html"/>
			<summary type="html"><![CDATA[<p>I have a comma delimited text file with several records. A typical record looks like this:</p><p>Jim,Smith,1234 Main Street,Anytown,NY,12345,206,123-3456</p><p>I need to read the file andd then output the data (name and phone number) in a two columm table like this:</p><p>Smith, Jim&nbsp; &nbsp; &nbsp; &nbsp; (206) 123-3456</p><p>The data also needs to be sorted by last name.</p><p>I assume I will be using an array, but I&#039;m not sure how to do it.</p><p>If you can help me, email me at grz@wi-net.com.</p><p>Thanks,</p><p>Andrew</p>]]></summary>
			<author>
				<name><![CDATA[andrewgrz]]></name>
				<uri>http://phpforums.org/user36.html</uri>
			</author>
			<updated>2010-06-06T02:00:09Z</updated>
			<id>http://phpforums.org/topic28-comma-delimited-file-new-posts.html</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[For beginners, where to learn?]]></title>
			<link rel="alternate" href="http://phpforums.org/topic24-for-beginners-where-to-learn-new-posts.html"/>
			<summary type="html"><![CDATA[<p>For all the beginners, where is the best place to learn about coding and, for that matter, anything related to getting started?</p>]]></summary>
			<author>
				<name><![CDATA[jaydesigns]]></name>
				<uri>http://phpforums.org/user16.html</uri>
			</author>
			<updated>2009-11-21T04:03:09Z</updated>
			<id>http://phpforums.org/topic24-for-beginners-where-to-learn-new-posts.html</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[if empty]]></title>
			<link rel="alternate" href="http://phpforums.org/topic21-if-empty-new-posts.html"/>
			<summary type="html"><![CDATA[<p>all clear for what is meant if(empty($field))</p><p>i dont like the fact that the field is no longer seen as empty if it consists even of one space</p><p>how to make that the field is empty although it would contain even 100 spaces?</p><p>thanks</p>]]></summary>
			<author>
				<name><![CDATA[Earl]]></name>
				<uri>http://phpforums.org/user7.html</uri>
			</author>
			<updated>2009-10-13T09:47:24Z</updated>
			<id>http://phpforums.org/topic21-if-empty-new-posts.html</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Header errors - read here before posting them!]]></title>
			<link rel="alternate" href="http://phpforums.org/topic19-header-errors-read-here-before-posting-them-new-posts.html"/>
			<summary type="html"><![CDATA[<p>i&#039;ve seen this error pop up time and time again, and the answer is ALWAYS the same.&nbsp; please look here before you post it.&nbsp; the problem is you are outputting to the browser (whitespace included) before sending a header.&nbsp; this is unallowed.&nbsp; remove output prior to the header, or use OUTPUT BUFFERING.</p><p>NEW EDIT TO THIS TOPIC:</p><p>what usually results in these errors is poor script design.&nbsp; when one processes a form, they should do it BEFORE OUTPUTTING ANYTHING TO THE BROWSER.&nbsp; there is NO reason that the process cannot be operated in the header of the document, before any HTML is output.</p><p>let&#039;s take a common example.&nbsp; the programmer wants a login form which checks the username and password against the database.&nbsp; if they don&#039;t match, then don&#039;t set a cookie remembering them and tell them it failed.&nbsp; if they do match, set the cookie and send them to a member page.&nbsp; many will do:</p><p>[HTML starting the page and layout]<br />[PHP processing the form]<br />[form code]</p><p>because they can simply echo any errors straight from PHP right above that form.&nbsp; they can also send a success message, set the cookie, and header() them off on their merry way without seeing the form again.&nbsp; it&#039;s a logical place to put this code.&nbsp; think again.&nbsp; you&#039;ll (perhaps not so) obviously get header errors when you go to use setcookie() and header().&nbsp; if the login fails, it&#039;s dandy, but if you have a successful login the user gets nowhere.</p><p>answer:&nbsp; put the processing in the header, and store the results in variables.&nbsp; perhaps a $result variable that is 1 if successful, 0 if failed.&nbsp; then $output that contains either a success message or customized error messages.&nbsp; the new code would look like:</p><p>[PHP processing the form (if it was sent) and storing the results]<br />[HTML starting the page and layout]<br />[PHP echoing the results]<br />[form code if failed - exit(); if successful]</p><p>this will solve your header errors and will make for much more maintainable and readable code.&nbsp; if you want to redirect them elegantly (with a success message), use a &lt;meta&gt; refresh redirect.&nbsp; header() should only be used in instances where instant redirection is desired.</p>]]></summary>
			<author>
				<name><![CDATA[jaydesigns]]></name>
				<uri>http://phpforums.org/user8.html</uri>
			</author>
			<updated>2009-10-10T01:27:46Z</updated>
			<id>http://phpforums.org/topic19-header-errors-read-here-before-posting-them-new-posts.html</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[if and else]]></title>
			<link rel="alternate" href="http://phpforums.org/topic5-if-and-else-new-posts.html"/>
			<summary type="html"><![CDATA[<p>hi</p><p>how would i make an if statement so if first variable is the same as second variable it displays the word &quot;same&quot; and if they are different it displays the word &quot;different&quot;</p><p>thanks</p>]]></summary>
			<author>
				<name><![CDATA[jaydesigns]]></name>
				<uri>http://phpforums.org/user7.html</uri>
			</author>
			<updated>2009-10-07T15:15:19Z</updated>
			<id>http://phpforums.org/topic5-if-and-else-new-posts.html</id>
		</entry>
</feed>
