Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 2nd, 2004, 7:59 PM   #1
nisim
Newbie
 
Join Date: Nov 2004
Posts: 2
Rep Power: 0 nisim is on a distinguished road
I'm currently learning PHP which is my first programming/scripting language. I know html/css rather well and am grasping the concepts of PHP pretty well too. I have sort of hit a "plateau" of sorts though. This comes from a lack of understanding conceptualy not with syntax. You see, I'm a quite logical thinker but the concept of programming is elluding me. I know that it is just giving a dumb machine a bunch of commands but that's it.

I can't really put it fully in words but could someone maybe help me with the logic/concept behind programming? As it stands, I can follow simple programming rules but have no design concept. If I were asked to write, say, a user login script I would be totally lost. I just can't yet grasp building a script/program from the ground up. I know that this is an intergal part of being a good programmer so any help/ideas?

Any suggestions on just great tips that helped you all in learning your first languages would be helpful too.

thanks
nisim is offline   Reply With Quote
Old Nov 2nd, 2004, 9:09 PM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
-shove-

Alright moving on. Basically when you are writing a program you have to decide what all the code will need to have in it to work....

For a login script:
- Input to the PHP page (user and pass variables)
- Connection to the databases with user and pass variables stored
- Check to make sure that user exists
- If he does then start a session in which identifies him as logged in...

<?php
  /* 
   * The following is a very basic login.php
   * because of the risk of MySQL injection
   * and the lack of MD5 encryption in the
   * database this shouldnt be used for a
   * commercial site. This is merely a backbone
   * example.
   */

  // (1) Get the variables from the forms
  // that sent us info VIA post.
  $user = $_POST['user'];
  $pass = $_POST['pass'];

  // (2) Make a mysql database connection
  mysql_connect("localhost", "user", "pass");

  // (2 a) Select the db with the user and pass table in it
  mysql_select_db("users");

  // Query the mysql database and make $query hold our results 
  $query = mysql_query("select * from users where user = '{$user}' and pass='{$pass}'");
 
  // See if any rows were returned, identifying the user and pass as being existant in the db
  if(mysql_num_rows($query) > 0) {
    // Start our session...
    session_start();
 
    // Set our session user
    $_SESSION['user'] = $user;
  }
?>

The best programming practice exists in challenging yourself with the knowledge you have to create programs that are a little bit out of your reach, but not too much to where you cant accomplish it.
__________________

tempest is offline   Reply With Quote
Old Nov 2nd, 2004, 9:50 PM   #3
BlazingWolf
Hobbyist Programmer
 
Join Date: Sep 2004
Posts: 207
Rep Power: 5 BlazingWolf is on a distinguished road
-shove-

I'm not sure exactly what your getting at but I from what I get your having problems with thinking of program design and how to go about attacking a full fledged script.

Pretty much like what tempest said I like to break down exactly what has to happen. Roughly at first, and then go inside each step and say EXACTLY what needs to happen for this step to work and to get you to the next step.

Then once you have all your steps down you may very well, especially with a login script, need more than one file. So you look at each file and then begin to write out your steps, except in syntax and not words.


I tried my best . Hope that helps you a bit.
__________________
_______________________________
BlazingWolf
BlazingWolf is offline   Reply With Quote
Old Nov 3rd, 2004, 7:21 AM   #4
scorpiosage
Programmer
 
scorpiosage's Avatar
 
Join Date: Aug 2004
Location: Austin, Tx
Posts: 55
Rep Power: 5 scorpiosage is on a distinguished road
Send a message via AIM to scorpiosage Send a message via Yahoo to scorpiosage
Having html and css background is good work. That's where I started, and then since then got a little inot C programming and vb programming (ok, I am not the best at those, but, know enough to do a few nifty tricks.).

As most of my focus has been in web development though, before I got into c and vb, I got onto Javascript.

The basics of javascript itself has tought me a lot about programming, and how scripts are formed.

Each language of course has it's own way of going about things, and it is in a way the same as English or any other language.

Before I sit down to actually create a script I first figure out what exactly I want it to do.

You can actually sit down and write it in story form wich will help you, for instance

when the dog barks the neighbors wake up. When the dog doesn't bark, the neighbors do not wake up.

In programming this sentence is usually stated differently though. It would read,

If the dog barks the neighbors wake up, otherwise, the neighbors do not wake up.

The problem is, that you actually have to define some of these words. In the english language everything has a deffinition. In programming, there are only some words that are defined, and the rest you have to actually define before you use them in your sentance.

For my explination here, what we need to define is the dog barking and the neighbors waking up, as well as the neighbors not waking up.

let us assume that we are getting the information from a form on a previous page, wich uses the post method (from an html form).

So would be the script.

<? 
$dog = $_POST['action'];

if ($dog =="bark")
print("the nieghbors wake up");
else
print9"the nieghbors do not wake up");
?>

Up until now this is a bit pointless, all that it does is print something based on wether or not the previous form posted "bark", but, this is the basic idea. Now you can do a bunch of different things based on the given information.
you can define the database connection and path, and insert weather or not the neighbor is barking into a database, so on and so forth.

I prefer to think of things in terms of nouns and verbs. For every action there must be something doing that action and all parts, if not defined under php's "dictionary" must be defined by using only words that are in php's dictionary.

In the previous example, we defined dog, by saying
$dog = $_POST['action'];

This assumes that the name attribute of the form field on the previous page was "action".

Now, if we had to create another deffinition for something, we can actually use the php dictionary and our own dictionary to define it. Anywhere were you would have to call the result of the form field "action" all you have to do is put $dog and you are good to go.

I hope that this served to help your logical side, because I truely am the same way. If things don't make sense, or I can't translate them into logic english then they just don't go anywhere for me iether.
Mike
__________________
Here's my latest project still in the works, and I need to get rid of this &quot;frame&quot; situation for real. www.prideofaustin.com
scorpiosage is offline   Reply With Quote
Old Nov 3rd, 2004, 10:27 PM   #5
nisim
Newbie
 
Join Date: Nov 2004
Posts: 2
Rep Power: 0 nisim is on a distinguished road
Hey, thanks guys for all of the help. It is really useful. Mike, your post was especially useful b/c it did help put it into logical english, which I now realize is what I need.
nisim is offline   Reply With Quote
Old Nov 3rd, 2004, 11:38 PM   #6
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
If you get a chance, pick up an O'Reilley book called "PHP Cookbook" it is an amazing cookbook that includes several approaches to the PHP login situation... it even shows you how to use HTAuthentication through PHP.

And it has many more receipes! And it is actually a fairly cheap book!
__________________
Clifford Matthew Roche &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Nov 4th, 2004, 8:39 AM   #7
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
I have it in ebook form.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Jan 10th, 2005, 3:33 AM   #8
scorpiosage
Programmer
 
scorpiosage's Avatar
 
Join Date: Aug 2004
Location: Austin, Tx
Posts: 55
Rep Power: 5 scorpiosage is on a distinguished road
Send a message via AIM to scorpiosage Send a message via Yahoo to scorpiosage
Pizentios,
where can one find that ebook?...lol
Nisim,
Well, it confused me too for a long while, and then through the help of this amazing board and the help of my new found best friend..lol.. who is a programmer. I am constantly grabbing new information and ideas.
I need to point him to this board though, but he doesn't have the patience for these boards.
Regardless, I am glad that something I said finally helped someone on here...lol...
Laters
Mike
__________________
Here's my latest project still in the works, and I need to get rid of this &quot;frame&quot; situation for real. www.prideofaustin.com
scorpiosage is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:55 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC