This is my first of I figure many threads. Before this year between Photoshop and Dreamweaver, I made HTML websites. I upgraded to notepad++ and Gimp/Photoshop and continued making HTML websites with occasional PHP for forms and such. I have my own private development server and it's not a recycled hp tower.

NOW, a friend and client has asked me to code the first iteration of what they hope will become a premier resource on the web, but I don't know PHP! I'm getting along alright, but want to truly learn php, not just copy and paste from forums and textbooks.

SO, where/how did you learn php?

It depends on your style and how you learn. Some people seem to need the structure of a formal course and textbooks. I like to jump in and thrash around until I figure it out. I think that I bought a book for reference but mainly it was a lot of trying things, using the PHP manual/help file and doing web searches. I downloaded a lot of open-source systems so looking at how they work was helpful. I had the benefit of many years working in other languages so I already had the fundamentals, I just had to learn the language and the web environment.

I built a couple of systems that I provide as services to clients. There was a lot of on-the-job learning when I built them and I worked on them a long time before I got to release 1 (1 - 1.5 yrs in total). I'm still learning and there are things like oop for PHP that I haven't really bothered with yet (but I might get around to it one of these days). When you get into it, you also need an adequate knowledge of CSS and it is good to be comfortable with using a Javascript library like JQuery. PHP is good for the back end but if you want to build something that is user-friendly, you need some front-end tools as well. Unless you're a genius, you can't do it over night. One short-cut is to use open-source code / systems wherever you can rather than build from scratch. There is a lot of good stuff available built by people who have already put in the years to learn how to do it properly. Even if you take it and have to modify it, you probably end up with a much better product much quicker than if you started from scratch (if you start with something that is pretty well structured).

The best way to learn is through trial and error. Think of projects that you want to create, and read up on how to create them. DaniWeb, Google and PHP.net will become your best friends. I tend to stray away from text books, as they do not teach you how to problem solve. Using them for references is fine, but you'll never actually learn anything by following the directions.

Everyone codes a little differently, and logic changes from person to person. When asking for help, though, be sure to be as specific as possible, especially when explaining the functionality you're attempting to create.

You define your own learning curve.

I signed an NDA, so I can't say much, but I'll say what I can. These suggestions so far have been helpful. One of the biggest problems is I broke the first rule of programming: I jumped in and started coding without a design, without a plan even. I started with a few CMS's... Junk. But I need some of their features... I tried Code Igniter, but was utterly unable to merge my existing code with the MVC model and get anything but blank pages... I broke the login and can't figure out how to fix it, and have no idea how to implement some of the features I know I will need... I absolutely LOVE classrooms although I don't learn anything I don't teach myself, but while my wife is at work, I work on this from home while I watch our son and fix PC's so college is out of the question, and O'Reilly's PHP MySQL and Javascript book was too slow... Any suggestions?

I hope I don't break my clients' confidence with this. Users will log in and post content related to the type of service we intend to provide, and will need to be able to (from some form of dashboard) edit the navigation of their profile. This is not a social networking site, no glittering GIF's or the like, but all sorts of content related to the user will be available on their "profile" and they need to be able to add to the existing site...

You'll have a pretty tough time looking for help if you signed a NDA. No offense, but if you don't know how to program, than you shouldn't have taken a serious project if you can't explain what you're doing. PHP, being Open-Source, is very susceptible to hacks and exploits if you don't know anything about security. So, first things first, start researching secure PHP code, because if this project is going to be heavily based on users logging in and out, you truly need secure code.

If you think the book was slow, than learning in a classroom environment would be even slower.

Personally, I learnt PHP from looking at other peoples code... then using php.net to research the functions =)

Hope this helps.

Dan

Well, I'll keep back as little as I can. From what I understand, the NDA is about the purpose of the site, but not the features (technology) it has in common with other sites. Should I start a new thread for help with say, the login? That is what is troubling me right now...

Well, I'll keep back as little as I can. From what I understand, the NDA is about the purpose of the site, but not the features (technology) it has in common with other sites. Should I start a new thread for help with say, the login? That is what is troubling me right now...

Login using PHP and MySQL?

Dan

Before posting a thread like that, search the forums. Login problems are common issues with PHP. I'll guarantee there are plenty of threads already created and solved on this forum regarding login with php and mysql.

Before posting a thread like that, search the forums. Login problems are common issues with PHP. I'll guarantee there are plenty of threads already created and solved on this forum regarding login with php and mysql.

This is very true, here is a simple one I made...

Call the code by

login($_POST['user'], $_POST['pwd']);

Here is the function

function login($user, $pwd){

	// Clean the items
	$user = $user;
	$pwd = md5($pwd);
	
	// Check against DB...
	$login_q = mysql_query("SELECT * FROM `users` WHERE email = '$user'");
	$login_r = mysql_fetch_assoc($login_q);
	
	if($login_r['pwd'] != $pwd){
		// Error
		echo "Invalid Login Details.";
	}else{
		
	if($login_r['status'] == "2"){
		echo "Your account is pending aproval!";
	}else{
		
	if($login_r['status'] == "6"){
		echo "Your account has been banned!<br>Please contact us!";
	}else{

		// Login
		// Make sessions
		$_SESSION['uid'] = $login_r['id'];
		$_SESSION['username'] = $login_r['username'];
		$_SESSION['email'] = $login_r['email'];
		$_SESSION['admin'] = $login_r['admin'];
		$_SESSION['last_log'] = time();
		$_SESSION['login'] = "yes";
		
		// Update details
		mysql_query("UPDATE `users` SET `ip_last` = '".$_SERVER['REMOTE_ADDR']."', `last_log` = '".time()."' WHERE `email` = '$user'");
		
		// Redirect
		echo "<meta http-equiv='refresh' content='0;URL=?view=mylocations' />";
	}}}
}
<?php // header.php
include 'functions.php';
session_start();
$error = $user = $pass = "";
global $user;
global $pass;
global $error;
global $query;
global $loggedin;
if (isset($_POST['user']))
{
	$user = sanitizeString($_POST['user']);
	$pass = sanitizeString($_POST['pass']);

	if ($user == "" || $pass == "")
	{
		$error = "Not all fields were entered<br />";
	}
	else
	{
		$query = "SELECT user,pass FROM members
				  WHERE user='$user' AND pass='$pass'";

		if (mysql_num_rows(queryMysql($query)) == 0)
		{
			$error = "Username/Password invalid<br />";
		}
		else
		{
			$_SESSION['user'] = $user;
			$_SESSION['pass'] = $pass;
			 echo "<meta http-equiv=\"Refresh\" content=\"0;url=members.php?view=$user\">";
		}
	}
}

if (isset($_SESSION['user']))
{
	$user = $_SESSION['user'];
	$loggedin = TRUE;
}
else $loggedin = FALSE;

echo "<html><head>
	<link rel=\"stylesheet\" href=\"css/style.css\" type=\"text/css\" media=\"screen\" />
  	<link rel=\"stylesheet\" href=\"css/slide.css\" type=\"text/css\" media=\"screen\" />
  	<!-- PNG FIX for IE6 -->
  	<!-- http://24ways.org/2007/supersleight-transparent-png-in-ie6 -->
	<!--[if lte IE 6]>
		<script type=\"text/javascript\" src=\"js/pngfix/supersleight-min.js\"></script>
	<![endif]-->
	 
    <!-- jQuery - the core -->
	<script src=\"js/jquery-1.3.2.min.js\" type=\"text/javascript\"></script>
	<!-- Sliding effect -->
	<script src=\"js/slide.js\" type=\"text/javascript\"></script>
<title>$appname";
if ($loggedin) echo " ($user)";

echo "</title></head><body>
<!-- Panel -->
<div id=\"toppanel\">
	<div id=\"panel\">
		<div class=\"content clearfix\">
			<div class=\"left\">
			<p class=\"grey\">The logo will go here</p>
			</div>
				<div class=\"left\">
				<h1>Welcome to $appname</h1>";
				if ($loggedin)
{
	echo "<h2>Hello $user!</h2><br />";
}
else
{
	echo "<h2>Hello Guest!</h2><br />";
}
				if ($loggedin)

{
	echo "<a href='members.php?view=$user'>Home</a><br />
		 <a href='members.php'>Members</a><br />
		 <a href='friends.php'>Friends</a><br />
		 <a href='messages.php'>Messages</a><br >
		 <a href='profile.php'>Profile</a><br >
		 <a href='logout.php'>Log out</a>";
}
else
{
	echo "<a href='index.php'>Home</a><br />
		 <a href='signup.php'>Sign up</a><br />
		 <a href='login.php'>Log in</a>";
}
			echo "</div>
			<div class=\"left right\">";
			if ($loggedin)
			{
				echo "<p class=\"grey\">Site news or something else could go here.</p>";
			}
			else {

				echo "<!-- Login Form -->
				<form class='clearfix' method='post' action='header.php'>$error
					<h1>Member Login</h1>
					<label class='grey'>Username:</label>
					<input class='field' type='text' name='user' value='$user' maxlength='16' />
					<label class='grey'>Password:</label>
					<input class='field' type='password' name='pwd' id='pwd' value='$pass' maxlength='16' />
	            	<label><input name='rememberme' id='rememberme' type='checkbox' checked='checked' value='' /> &nbsp;Remember me</label>
        			<div class='clear'></div>
					<input type='submit' name='submit' value='Login' class='bt_login' />
					<a class='lost-pwd' href='#'>Lost your password?</a>
				</form>";
			}
			echo "</div>
		</div>
</div> <!-- /login -->	

	<!-- The tab on top -->	
	<div class=\"tab\">
		<ul class=\"login\">
			<li class=\"left\">&nbsp;</li>";
if ($loggedin)
{
	echo"<li>Hello $user!</li>";
}
else {
	echo "<li>Hello Guest!</li>";
}
echo "<li class=\"sep\">|</li>
			<li id=\"toggle\">
				<a id=\"open\" class=\"open\">Expand</a>
				<a id=\"close\" style=\"display: none;\" class=\"close\">Collapse</a>			
			</li>
			<li class=\"right\">&nbsp;</li>
		</ul> 
	</div> <!-- / top -->
	
</div> <!--panel -->
<font face='verdana' size='2'>";
?>

that is the new situation (broken)
the old is

<?php // login.php
include_once 'header.php';
echo "<h3>Member Log in</h3>";
$error = $user = $pass = "";

if (isset($_POST['user']))
{
	$user = sanitizeString($_POST['user']);
	$pass = sanitizeString($_POST['pass']);
	
	if ($user == "" || $pass == "")
	{
		$error = "Not all fields were entered<br />";
	}
	else
	{
		$query = "SELECT user,pass FROM members
				  WHERE user='$user' AND pass='$pass'";

		if (mysql_num_rows(queryMysql($query)) == 0)
		{
			$error = "Username/Password invalid<br />";
		}
		else
		{
			$_SESSION['user'] = $user;
			$_SESSION['pass'] = $pass;
			 echo "<meta http-equiv=\"Refresh\" content=\"0;url=members.php?view=$user\">";
		}
	}
}

echo <<<_END
<form method='post' action='login.php'>$error
Username <input type='text' maxlength='16' name='user'
	value='$user' /><br />
Password <input type='password' maxlength='16' name='pass'
	value='$pass' /><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
<input type='submit' value='Login' />
</form>
_END;
?>

and

<?php // header.php
include 'functions.php';
session_start();

if (isset($_SESSION['user']))
{
	$user = $_SESSION['user'];
	$loggedin = TRUE;
}
else $loggedin = FALSE;

echo "<html><head>
	<link rel=\"stylesheet\" href=\"css/style.css\" type=\"text/css\" media=\"screen\" />
  	<link rel=\"stylesheet\" href=\"css/slide.css\" type=\"text/css\" media=\"screen\" />
  	<!-- PNG FIX for IE6 -->
  	<!-- http://24ways.org/2007/supersleight-transparent-png-in-ie6 -->
	<!--[if lte IE 6]>
		<script type=\"text/javascript\" src=\"js/pngfix/supersleight-min.js\"></script>
	<![endif]-->
	 
    <!-- jQuery - the core -->
	<script src=\"js/jquery-1.3.2.min.js\" type=\"text/javascript\"></script>
	<!-- Sliding effect -->
	<script src=\"js/slide.js\" type=\"text/javascript\"></script>
<title>$appname";
if ($loggedin) echo " ($user)";

echo "</title></head><body>
<!-- Panel -->
<div id=\"toppanel\">
	<div id=\"panel\">
		<div class=\"content clearfix\">
			<div class=\"left\">
				<h1>Welcome to $appname</h1>
				<h2>Lorem ipsum dolor sit amet</h2>		
				<p class=\"grey\">consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
				<h2>Download</h2>
				<p class=\"grey\">Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
				<p class=\"grey\">Navigation will go here</p>
			</div>
			<div class=\"left\">
				<!-- Login Form -->
				<form class=\"clearfix\" action=\"login.php\" method=\"post\">$error
					<h1>Member Login</h1>
					<label class=\"grey\" for=\"log\">Username:</label>
					<input class=\"field\" type=\"text\" name=\"log\" id=\"log\" value=\"$user\" maxlength=\"16\" />
					<label class=\"grey\" for=\"pwd\">Password:</label>
					<input class=\"field\" type=\"password\" name=\"pwd\" id=\"pwd\" value=\"$pass\" maxlength=\"16\" />
	            	<label><input name=\"rememberme\" id=\"rememberme\" type=\"checkbox\" checked=\"checked\" value=\"forever\" /> &nbsp;Remember me</label>
        			<div class=\"clear\"></div>
					<input type=\"submit\" name=\"submit\" value=\"Login\" class=\"bt_login\" />
					<a class=\"lost-pwd\" href=\"#\">Lost your password?</a>
				</form>
			</div>
			<div class=\"left right\">			
				<!-- Register Form -->
				<form action=\"#\" method=\"post\">
					<h1>Not a member yet? Sign Up!</h1>				
					<label class=\"grey\" for=\"signup\">Username:</label>
					<input class=\"field\" type=\"text\" name=\"signup\" id=\"signup\" value=\"\" size=\"23\" />
					<label class=\"grey\" for=\"email\">Email:</label>
					<input class=\"field\" type=\"text\" name=\"email\" id=\"email\" size=\"23\" />
					<label>A password will be e-mailed to you.</label>
					<input type=\"submit\" name=\"submit\" value=\"Register\" class=\"bt_register\" />
				</form>
			</div>
		</div>
</div> <!-- /login -->	

	<!-- The tab on top -->	
	<div class=\"tab\">
		<ul class=\"login\">
			<li class=\"left\">&nbsp;</li>";
if ($loggedin)
{
	echo"<li>Hello $user!</li>";
}
else {
	echo "<li>Hello Guest!</li>";
}
echo "<li class=\"sep\">|</li>
			<li id=\"toggle\">
				<a id=\"open\" class=\"open\">Expand</a>
				<a id=\"close\" style=\"display: none;\" class=\"close\">Collapse</a>			
			</li>
			<li class=\"right\">&nbsp;</li>
		</ul> 
	</div> <!-- / top -->
	
</div> <!--panel -->
<font face='verdana' size='2'>";
echo "<h2>$appname</h2>";

if ($loggedin)
{
	echo "<b>$user</b>:
		 <a href='members.php?view=$user'>Home</a> |
		 <a href='members.php'>Members</a> |
		 <a href='friends.php'>Friends</a> |
		 <a href='messages.php'>Messages</a> |
		 <a href='profile.php'>Profile</a> |
		 <a href='logout.php'>Log out</a>";
}
else
{
	echo "<a href='index.php'>Home</a> |
		 <a href='signup.php'>Sign up</a> |
		 <a href='login.php'>Log in</a>";
}
?>

What's broken? (ie: what errors do you get? what lines numbers?) Please be more specific when asking for help.

The above code is also using jQuery, which if you don't know PHP, you're not going to understand jQuery at all. IMO, you've picked a CMS/Login Script that is far too advanced for you. Dumb things down a little and start small and work your way up.

as the code is I get error "Notice: Undefined index: pass in /var/www/bones/alpha_3/barium/header.php on line 13" if I change action to login.php from header.php, I get the original log in page. By the way, the jquery script works great, and I know enough to change it from clicking to mouse enter and mouse leave... Is the error because I am trying to move the login inside the jquery slider? It's from "web-kreation"...

I started the entire project with the example code from the O'Reilly book I finished... I would like to believe I understand that code, but modifying it starts problems... I modified it for navigation on 5 different alpha versions, even modified the login and signup forms, the jquery slider is the only time I literally "moved" the code... But nothing I do can fix the login on the jquery alpha so far...

I am only willing to PM links to the pages in action as they are on my private server, and I do not want any search engines indexing my server... But if anyone wants to see what I am working on in order to help me (there are no trade secrets in any of the alpha code yet), I will send a link...

undefined index means that the variable ($pass) is called, but is empty, meaning that $pass isn't set.

if (isset($_POST['user'] && ($_POST['pass']))
{
$user = sanitizeString($_POST['user']);
$pass = sanitizeString($_POST['pass']);

Ok, my simple impression of the original login script is that after $user and $pass are set by the form (at the bottom), the script starts at the top and checks them against the db. So in the same order, processing on top and form below, I moved them into the header where the nav is, and figured it would start at the top again?

I highly suggest using a much more simplistic login system. This example also stores your password as $_SESSION data which I'm fully against.

Show your header file.

on the previous page I posted the modified non-working header.php, followed by a working (minus login) header.php, and the original login script login.php

Well, the basics of php that I learned was from my Instructor way back 2010 when i was in 3rd year college 2nd sem. The first time that i made my own php that my instructor gave us some activity, I googled some basics and this is the site where you can understand php easily "http://www.w3schools.com/php/".

From trying 2 other login systems, and getting the same error, I would gather that the if/else that the login form is nested in is nested in within the jquery slider.

if ($loggedin)
			{
				echo "<p class=\"grey\">Site news or something else could go here.</p>";
			}
			else {

				echo "<!-- Login Form -->
				<form class='clearfix' method='post' action='$resultpage'>
					<h1>Member Login</h1>
					<label class='grey'>Username:</label>
					<input class='field' type='text' name='user' value='$username' maxlength='16' />
					<label class='grey'>Password:</label>
					<input class='field' type='password' name='pwd' id='pwd' value='$password' maxlength='16' />
	            	<label><input name='rememberme' id='rememberme' type='checkbox' checked='checked' value='' /> &nbsp;Remember me</label>
        			<div class='clear'></div>
					<input type='submit' name='submit' value='Login' class='bt_login' />
					<a class='lost-pwd' href='#'>Lost your password?</a>
				</form>";
			}

I actually learned PHP by accident, you see we've had a lousy professor in our Database management class, not only being lousy he demanded projects so bad,Tons of homeworks, and other pain in the ass crap that professors give, and then He gave us a project where we will create a database, my groupmates and I thought that we should make something different, something big, rather than making some mediocre work or just for the sake of passing that subject.We've decided to make a website where it will Store data in the database, we've made research, and we found out that PHP is the language that will suit us, soo by that I studied PHP.and because of that I am starting to love PHP, since it's user friendly and on the plus side I love the way it declare variables with a "$" it reminds me of ke$ha lol

Member Avatar for diafol

Is it me, or has this thread gone off-piste big style? Why is there code in it? Looking at the OP, the question seems pretty straightforward. Anyway. Here's mine:

I started with old Qbasic, Basic, VisualBasic5,6. I realised that VB was 'useless' for the new fangled web thingy. I started with SSI and tried to get to grips with ASP. Support was non-existent, so I started messing with PHP.

I bought a few textbooks from Wrox and O'Reilly. Now I'm hooked.

If you want a beginner's crash course then I'd suggest you 2 places:

1. PHP Academy on Youtube and
2. W3Schools

Then you can move onto expert level tutorials easily...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.