Jump to content

Recommended Posts

RIGHT!!

It Has Been A Year Since I Started Trying To Learn PHP And I Have Had Enough Of Saying Im A Noob Needing Help N Then Getting A oad Of Technical Talking Thrown Down My Gob Like Im So Pro.

I Have Also Seen Alot Of People In My Position-Being Given Code To Use But Never Understanding It.

IT STOPS HERE!

I Have Made This Topic So That Noobs Like Me Can Get Basic Things In Php Explained To Us In The Most Simple Way They Can.

I Am Asking Everyone Out There To Help Us Noobs By Explaining Things In Very Simple Terms-To Help Us Understand Things Easier And Stop Us Having To Ask People For Coding Help.

Firstly-I Would Like To Know What These Are In The Simplest Way Possible.

Arrays
Strings
How To Store Cookies In A Browser For A Log In Script (Which Time Out After Inactivity On The Particular Site).
when , should be used and why
when () should be used and y
when {} should be used and y
when " should be used and why
when ' should be used and why (i know its a string thing but thats all)

Please If You Are A Noob Or Not But Need Help-Explain What You Need Help With.

If You Are Here To Explain-Please Keep It Simple-I Feel If This Topic Goes As Planned-Alot Of People Will Be Helped.

Thank You All

Pudgemeister
  • Replies 117
  • Created
  • Last Reply

Top Posters In This Topic

Unfortunately, what you are asking are the very basics of PHP. (And in a lot of cases, other programming languages.) Now, if you have spent 1 year learning PHP, and do not know when "{" should be used, or what Arrays are...then you have not applied yourself. I believe your lack of understanding, is due to an "I want to learn quick with no work" approach to things. This might not be accurate but, is true most of the time. What those things do, can be learned by doing no more than 30 mins of research and reading.

Please visit: http://www.php.net

It's a great resource and there's more than enough there to learn those things you are asking about. Being a newbie is all well and good...but a lot of us here learned what we did via lots of work and time invested.
[b]Arrays[/b]: Groups of items (numbers, characters, strings, etc).  The reason we use arrays is so we can loop through items quickly and process them faster.  If I didn't use an array, i'd be doing something like this:

$myvar1 = 1;
$myvar2 = 2;
$myvar3 = 3;

With an array, you can do this:
$myvar = array(1,2,3);
or
<?php
for($i=0;$i<10;$i++)
  $myvar[] = $i;
print_r($myvar); // prints out the array values
?>

Then you have access to all those values through the same variable.

[b]Strings:[/b]
Strings are just groups of characters put together to form words.  I'm not sure what the question is here, but this could be very broad.  Maybe you can elaborate on what you want?  There's not much typecasting in PHP, so the topic is vague.

[b]setcookie()[/b]
I recommend looking it up in the manual.  I don't think anyone can explain it any easier.  www.php.net

[b]operators[/b]
, - Not sure why you're using them... usually to seperate lists.  I can't think of much else!?
() - Their use is usually optional.  I know some people that use them around echo/print statements, but you don't need to.  They are required when making a call to a function.
{} - necessary if using an if or a loop statement that contains more than one line.  Most people use them regardless as good coding practice, but they're not absolutely required unless you're going beyond one line.
quotes - Use double quotes in an echo if you want to just put your variables straight in there (e.g. echo "this is my $var";)  Use single quotes if you're using HTML tags just to make it easier (e.g. echo '<img src="here.gif" alt="test">';)

There are a bunch of other examples I could throw out, but I'll let someone else add to this post.
Arrays
Strings
How To Store Cookies In A Browser For A Log In Script (Which Time Out After Inactivity On The Particular Site).
when , should be used and why
when () should be used and y
when {} should be used and y
when " should be used and why
when ' should be used and why (i know its a string thing but thats all)

------------------

1. Arrays are a group of variables which share the same name.  Each element is accessed by a numerical or associative key:  $array[0] or $array['banana'], forexample
2. A string is a block of text, to put it basically.  "This is a string"
3. Don't use cookies, use sessions.  Read the phpfreaks session articles for more details.
5. Commas seperate parameters and loop arguments.
5. Parentheses set off various information, such as function parameters, loop conditions, etc:  function newFunction(parameter1, parameter2)
6. Braces are used to block off if/else statements, functions, loops, and other things.  if(statement=true){run the code inside the braces if the statement is true}

Quotes are more complex than what I'm about to write, but in general the confusion between the two is this:

7. Double quotes are used for interpolation in strings, which means variables can be placed inside the string and it will still be processed: $variable = red; echo "My car is $variable" will output "My car is red".
8. Single quotes are used in strings for concatenation, which means the above example would return "My car is $variable" without processing the PHP inside the single quotes.  You must concatenate instead with single quotes:  'My car is' . $variable  (The period serves as glue and joins the two value types together into one string.)

That was typed very fast and may be a bit sloppy.  However, if you are unfamiliar with any of the vocab in that, you need to learn it because you can't just avoid the "technical" side of PHP... you will see/hear those terms for as long as you code.  Another suggestion is to look up these topics on the phpfreaks site.
I too have been learning PHP for about 1 year.  Although I have background in various programming languages, the online help is so helpful.  

I have found the hardest part of programming is figuring what it is you want.  This is up to you!  

Then when you have figured that out, then finding out what the php functions are available to you to accomplish the task.  For that you can come here.  Most of these guys if not all have run into that or know about it and can point you in the right direction of what functions to use.  

Now you know what you want and what to use.  Now it is time to figure out how those functions work.  It is up to you to look them up in the manual.  They tell you the syntax and what the function does.  Even better they give plenty of examples of using the function in real code that is usually well documented.  

Once you learn what the function does, apply it.  When it doesnt work, come back here and ask why!  

One step at a time, and you will catch on quickly.  Quit using the code people give you and paste into your code.  Figure out what it does and why!  This is how I learned and I think I caught on rather quickly.  It's a lot of work, but worth it!
[quote author=ober link=topic=102480.msg406735#msg406735 date=1154376660]
$myvar1 = 1;
$myvar2 = 2;
$myvar3 = 3;

With an array, you can do this:
$myvar = array(1,2,3);
or
<?php
for($i=0;$i<10;$i++)
  $myvar[] = $i;
print_r($myvar); // prints out the array values
?>

[/quote]

The For Loop:
In this case you are starting the loop off by setting i=0, you are looping until i reaches 10, after each loop add 1 to i (You can also use $i = $i + 1, or if you are taking one away you can use $i-- or $i = $i - 1)

Anything in the body of the loop is the stuff that is getting processed.

Programming can be very dry or very creative and a lot of fun.

if($php == "dry"){
  $outcome = "You aren't having enough fun.";
}elseif($php == "interesting" && $php == "inspiring"){
  $outcome = "You are having fun!";
}else{
  $outcome = "You might be having fun, you might not...read the manual!";
}

just a little example for the hell of it  8)

-Chris
I'm almost the newest PHP newbie with all of five days experience and I found a simple little book called PHP with MySQL by Nat McBride ISBN: 0340905565.  It cost me £10 in Oxford, UK and it's a great little introduction to the subject.  Now I know there's lots of info on the net but sometimes it's nice to sit down away from the PC and look over a book because, when you're starting out, it's good to have an overview of a subject rather than diving into the detail of a particular problem.  I know there are more technical books on the subject, and probably better ones overall, but this little paperback covers most of the things you asked about I think.  
You can also look around the internet and find some well written and documented tutorials. Once you know what you want and what you are looking for it should be pretty easy.

Just remember that Ebay, Amazon, and whoever else...wasn't built in a few days...be patient and focused and everything will come.

-Chris
that is acytually y i am getting into php.

i am hoping to within a few years to have written a php script that drives a text based rpg (like [url=http://ogame.org]ogame.org[/url]).

thankfully i am starting college this year and will be doing it for 4 years learning php in parts of these years.

i am then thinking to help this little game i have got here i could go onto college to do a coding course-just dont know (if ne) what ones there are yet.

neway keep the basics coming people-theres alot of satisfaction in this topic

Pudgemeister
if( $x != $y)

This is basic programming, not just basic PHP but basic C and Javascript too. If you are just starting out learning PHP this forum should not be your first port of call. I recommend getting hold of a book like PHP and MySQL for Dynamic Web Sites by Larry Ullman, or if you're feeling a bit more confident, PHP and MySQL Web Development by Welling and Thomson. I have these beside me always, especially the latter - books like these are your bible when getting started.
if ($X != 1) {
// do this
}

or

if ($X != 1) {
// do this
} else {
// do this if it is equal to 1!
} // end if/else statement

I have been doing php for 2 months? with prior html experience and I have already made a basic forum system with user registration, login/logout, posting threads, posts, edit posts, where the user is on the board, profile view, memberlist, etc.

Although this I would like to know how to do:
How To Store Cookies In A Browser For A Log In Script (Which Time Out After Inactivity On The Particular Site).
Or make sessions time out after inactivity.
right i have now.

i need to know how to add a minimum character limit to a password field so that the minimum password length is as much as i want it to be.

also-i need to know how to make it so the code only processes the passord if it has alphanumeric vailue inputted by the person registering.

thanx people-will read tomorow.

Pudgemeister
ok i would like to know how to do the above-but this is more important now:

i have these three files-index.php, login.php logged_in.php-and a databse with a table called users and fields: id (auto_increment), first_name, last_name, username, password, mail.


[u][b]index.php:[/b][/u]

[code]<?php
//Title//
echo '<center>Game Testing</center><br><br><br>';
//Register Form//
echo 'Register';
echo '<form action="register.php" method="post">';
echo 'First Name:<input type="text" name="first_name"><br>';
echo 'Last Name:<input type="text" name="last_name"><br>';
echo 'Username:<input type="text" name="username"><br>';
echo 'Password:<input type="password" name="password"><br>';
echo 'Confirm Password:<input type="password" name="password2"><br>';
echo 'E-Mail:<input type="text" name="mail"><br>';
echo 'Confirm E-Mail:<input type="text" name="mail2"><br>';
echo '<input type="Submit" value="Register Me"></form><br><br><br>';

//Login Form//
echo 'Login';
echo '<form action="login.php" method="post">';
echo 'Username:<input type="text" name="username2"><br>';
echo 'Password:<input type="password" name="password2"><br>';
echo '<input type="submit" value="Log In"></form>';

?>[/code]

[b][u]login.php:[/u][/b]

[code]<?php

include ("dbinfo.inc.php");

$username=$_POST['username2'];
$password=$_POST['password2'];

$query_1="SELECT id FROM users WHERE username=='$username' & password=='$password'";
$result_1=mysql_query($query_1) or die(mysql_error());
$num=mysql_num_rows($result_1); // returns numbers of matches found.

if ($num_1===0) {
    echo 'Your Password And/Or Username Are Not Correct-Please Try Again <a href="index.php">Here</a>';
    } else {

$query_2="SELECT id FROM users WHERE username='$username'";
$result_2=mysql_query($query_2) or die(mysql_error());
$id=mysql_num_rows($result_2); // returns numbers of matches found.

echo "$id";
session_start();
$_session['$id']='$username';
};
?>[/code]

[b][i]logged_in.php:[/i][/b]

[code]<?php

session_start();

echo 'Hello '.$_SESSION['$id'];

?>[/code]


In The Table Fields In The Table "users" I Have (In This Order-id, first_name, last_name, username, password, mail,) Adam, Trudgeon, Pudgemeister, login_test, myemail@adress.com.

now when i log in using ANYTHING as a username and password, it takes me to login.php and displays all this:

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=='gfdsgsgs' & password=='sgdsdgfsgfd'' at line 1"

and when i use my normal username and pasword it still displays this:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=='Pudgemeister' & password=='login_test'' at line 1.

I also know there are more errors in the code as before i did something that i cant remember, it logged you in no matter what your usrname and password was but with a WARNING error on the page (sometimes 2)

anyone know the prob(s) i have got here?

Cheers

Pudgemeister.

P.S. try and keep things simple-i made this topic to help noobs like me-things need to be explained with simple lang-nuthin to technical lol.
ok now i get this on login.php:

1
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/pudgesuk/public_html/game_testing/login.php:20) in /home/pudgesuk/public_html/game_testing/login.php on line 21

at least its echo'd the id but i dont know whats going on now-something wrong with the sql? i cant see what.

help please

Pudgemeister
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.