Honesty Rocks! truth rules.

Functions ???

HOME      >>       Programming

alex1985

I created this topic mainly because I wanna get a clear interpretation about those listed PHP functions.

 

The first function is while($row=mysql_fetch_array($query)) {


Erdemir

I created this topic mainly because I wanna get a clear interpretation about those listed PHP functions.

 

The first function is while($row=mysql_fetch_array($query)) {


You have called a sql and loaded it into variable $query. And by that line, you have loaded all coulombs into the variable $row as an array from the variable $query.

After this, it is easy to call a coulomb by the variable $row. For example: if there is a coulomb "username" in the table, you can call it by $row['username'] . This is the easiest way to call a coulomb. And each while repeats the next row will be loaded into the variable $row until all rows finishes.


alex1985

Explain me the following line;

$user=trim($_POST['user'])


Erdemir

Explain me the following line;$user=trim($_POST['user'])


trim function is a combine of left trim and right trim. trim deletes the spaces in the left and in the right of the variable.
Here variable $user has been set to $_POST['user'] without spaces around it.
For example: $_POST['user'] is
' user\'s name '
trim function will give you the result
'user\'s name'
and set it to $user.

alex1985

I did not get it clearly! For which puposse the function is used?!


Erdemir

I did not get it clearly! For which puposse the function is used?!

The trim function erases the spaces,tabs, at the start and at the end.

 

For example: in your code:

1. if ($_GET['login']) { #checks for admin login2. $user=trim($_POST['user']); #trim user in case of mistake3. $pass=trim($_POST['pass']);4. str_replace("username", "password", $srt);5. if (($user == "username") && ($pass="password")) {
Think that the user's name is
"username"
.

 

If the member enters

" username "
//there are some spaces at the beginning and end.

And if you didn't use trim and directly set, like this

2. $user=$_POST['user'];

At the 5th line the user's name will not equals. Like this

 

if (" username "=="username") {
the two value is not equal but

 

if you used trim function

2. $user=trim($_POST['user'];)
and so

if ("username"=="username") {
yes the two value is equal, because we used trim function.

 

 

Briefly if you use trim, the if match will be true even the member adds around the his username.


alex1985

Thanks. I think I am going to try it soon and then post a reply concerning such issues.


moodsey211

Thanks. I think I am going to try it soon and then post a reply concerning such issues.

try using php's documentation. it might help you on some other issues you have in mind.

 

http://php.net/docs.php


gogoily

You will find lots of useful and basic documents in this website:

http://php.net/


Lightning73

Yeah, just use http://php.net/ to search for most functions. Or if you need a different function just google it. Or ask here. Whichever you are most comfortable with.