/    Sign up×
Community /Pin to ProfileBookmark

learning PHP from w3school.

what does this code means

[CODE]
<?php
$con = mysql_connect(“localhost”,”peter”,”abc123″);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}

// some code
?>

[/CODE]

what does mysql_connect returns ? does it return boolean value ? i guess so because i see the usage if (!$con) .

[U]Where do i get the return type of these functions ?[/U]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiSep 16.2009 — mysql_connect returns either a resource (in this case a database connection link) if connection was succesful, or boolean false if connection failed. Since in PHP a resource evaluates to true, the code is effectively saying, "if a valid connection was not established, tell the user what the error was then exit the program".

The best place to find what functions return etc is the PHP Manual. At the top of each function's page, you will see a summary of the function which details any parameters it takes as well as what it returns. It also gives examples of how to use the function. It is an invaluable resource - I've been programming with PHP for about 8 years and I still use it every day.
Copy linkTweet thisAlerts:
@cofactorauthorSep 16.2009 — I am learning PHP from link

tutorial link http://www.w3schools.com/PHP/php_post.asp



[B]The $_POST Function[/B]

The built-in $_POST function is used to collect values from a form sent with method="post".

Example:

<form action="welcome.php" method="post">

Name: <input type="text" name="fname" />

Age: <input type="text" name="age" />

<input type="submit" />

</form>


[U]The "welcome.php" file can now use the $_POST function to collect form data (the names of the form fields will automatically be the keys in the $_POST array)[/U]:

[I]welcome.php[/I]

Welcome <?php echo $_POST["fname"]; ?>!<br />

You are <?php echo $_
POST["age"]; ?> years old.


see underline text i made.

does $_POST function and $_POST array are same ? How come a variable be both a function and array ?

i am NOT clear whether $_POST is function or array ? exactly confused here.
Copy linkTweet thisAlerts:
@MindzaiSep 16.2009 — Technically $_POST is not a function or an array - it is a superglobal. However it is easiest to think of it as an array which is available anywhere. More info in the manual. One thing it absolutely is *not* is a function.
Copy linkTweet thisAlerts:
@cofactorauthorSep 16.2009 — thanks ...that helped me a lot
Copy linkTweet thisAlerts:
@cofactorauthorSep 16.2009 — [B]tutorial link :[/B]

http://www.w3schools.com/PHP/php_date.asp

[CODE]PHP Date() - Adding a Timestamp

The optional timestamp parameter in the date() function specifies a timestamp. If you do not specify a timestamp, the current date and time will be used.

The mktime() function returns the Unix timestamp for a date.

The Unix timestamp contains the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.
Syntax for mktime()
mktime(hour,minute,second,month,day,year,is_dst)

To go one day in the future we simply add one to the day argument of mktime():

<?php
$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
echo "Tomorrow is ".date("Y/m/d", $tomorrow);
?>

The output of the code above could be something like this:
Tomorrow is 2009/05/12 [/CODE]


I dont understand the output .

let me analyse it

we have print of date("Y/m/d", $tomorrow);

"Y/m/d" -->gives 2009/05/12.

Now there is another part i.e $tomorrow .....where is the print for $tomorrow? [B][COLOR="Blue"]and if its not for printing then whats the role of of this $tomorrow here ? i am exactly stuck here .

[/COLOR]
[/B]
Copy linkTweet thisAlerts:
@JericoSep 16.2009 — $tomorrow is just a variable holding tomorrow's date value. You could rename $tomorrow to $whateveryouwant.

<?php

$whateveryouwant= mktime(0,0,0,date("m"),date("d")+1,date("Y"));

echo "Tomorrow is ".date("Y/m/d", $whateveryouwant);

?>
×

Success!

Help @cofactor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...