Jump to content
xisto Community
Sign in to follow this  
alex1985

Functions ???

Recommended Posts

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.

Edited by Erdemir (see edit history)

Share this post


Link to post
Share on other sites

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.
Edited by Erdemir (see edit history)

Share this post


Link to post
Share on other sites

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.

Edited by Erdemir (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.