Jul 26, 2008

php tutorial - basics...up to mysql/file commands

Free Web Hosting, No Ads > Have your say > General Talk

free web hosting

php tutorial - basics...up to mysql/file commands

welbis
the best way to start php is probably not adjusting a script IMO - that misses out a stage. - the very first stage biggrin.gif - here...

Why use php? because it allows things to be generated very quickly - without lots of html pages. It enables users you choose to allow, to input their own content to the pages you want them to.

1) save these files as anyfilename.php - pick your names, upload them to a php enabled server and go to the url they are at...

2) understand <?, ?>, .php, //////, /* */, and ;

CODE


<?



?>


THis tells the web browser when to expect php coding. So... when writing php, this needs to encase all php code - or it will be formatted as html.

Naming a filename .php allows for <? and ?> to be expected - or it will show as html.

CODE


<?

//// hello - this line will be overlooked



/* hello

these lines will be overlooked*/

?>



both of these 'hello's' will not be formatted as php - these 2 bits of code exclude the contained text.

CODE


<?

print "hello"

?>



print tells the php to print the contained text - if a variable is used then ""'s are not usually needed, if "" are used then the content will be shown as html. The above WILL NOT WORK. Each line of php code needs to be ended with a ;.

3) printing basic html

CODE


<?

print 'hello world';

?>



open the file - it will show the words hello world with no formatting.

4) printing and setting variables

CODE


<?

$hello = 'hello world';

///setting variables



print $hello;

///printing variables

?>




5) if else with variables

CODE


<?



$a = $_GET['a'];

///setting variables  (3)



if (isset($a)) {

print '<a href="?a=0">Click here</a><br>';

///printing html (2)



print "a is set to:".$a;

} else {

print '<a href="?a=1">Click here</a><br>';

///printing html (2)



print "a is empty";



}



?>




for a form... adjusting my last script from above...


6) create the form html - save as form.php.

CODE


<?

$form = <<<HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>Form!</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>



<body>

<form action="?a=1" method="post" name="" id="">

 <table width="50%" border="0" align="center" cellpadding="4" cellspacing="0">

   <tr>

     <td width="22%">Subject</td>

     <td width="78%"><input name="value" type="text" id="value"></td>

   </tr>

 </table>

</form>

</body>

</html>

<br>



HTML;

?>



that basically mates a text box to enter something into - which posts to ?a=1

then save the following as anythingyouwant.php .... load it...and should work as a simple form.
CODE


<?

include 'form.php';

///include the form we just made - so that you can print it when you need to.





$a = $_GET['a'];

///setting variables  - has the script been submitted yet? - get the value from the url



if (isset($a)) {

///the script has been submitted



$value = $_POST['value'];

///retrieve the posted data.



print '<a href="/?">Click here</a><br>';

///printing html - return to script not submitted



print "value is set to:".$value;



} else {

////form isnt submitted - so print it.

print "a is empty<br>";



print "therefore include the form<br><br>";

///printing html (2)



print $form;



}



?>




should work... unless i missed off a ; or something silly smile.gif (let me know below...if i have)


if you want to check the field to make it required - and show a form with a message if its not filled in, then this would be the edited version.....

CODE


<?

include 'form.php';

///include the form - so that you can print it when you need to.





$a = $_GET['a'];

///setting variables  - has the script been submitted yet?



if (isset($a)) {

///the script has been submitted



$value = $_POST['value'];

///retrieve the posted data.



if(isset($value)) {

/////////FIELD SET?////////////



print '<a href="/?">Click here</a><br>';

///printing html - return to script not submitted



print "value is set to:".$value;

} else {

//////FEILD NOT SET - show form again, with message to fill it out///////



print "The required fields are empty<br>";



print "therefore include the form<br><br>";

///printing html (2)



print $form;





}



} else {

////form isnt submitted - so print it.

print "a is empty<br>";



print "therefore include the form<br><br>";

///printing html (2)



print $form;



}



?>



then learn mysql and your sorted smile.gif


-----------------------
see database thread

 

 

 


Reply

Cosmic
Wow..... That tutorial is awesome !! Nice, simple, and efficient.

I'm just a bit lost at the

} else {

well.... I'm basicly confused at what the '}' or '{' characters do... :/

Reply

y04chs067
They start your statments

Reply

welbis
Cosmic,

anything within { } is what happens as a result of the previous statement.

That is to say

when you write
CODE


<?

if($a == 1) {

///anything within these tags happens WHEN $a = 1

}





if($a == 1) {

///anything within these tags happens WHEN $a = 1

} else {



/* anything within these tags happens when the IF statement returns false, or $a !==  (does not equal) 1 */



}



?>


Reply

M.C 2DEE
Thank you.
Mybe Ill start to learn PHP soon.

Reply

Rhoberan
You do know that you only need two slashes to start a single-line comment, right? 's just a bit weird to look at ...

Reply

welbis
yeah i do - i dunno why i do it like that, just a bad habit of mine

and I use different length slashes without text after them, between sections so that i can check which tag closes which more easily

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : php, basics, mysql, file, commands

  1. Secure File Transfer For Mainframe Systems
    (2)
  2. Will There Be A free Image, File, Video And Flash Host?
    (5)
    Do you think there will ever be a free Image, File, Video, and flash host all on one site? I doubt
    there is, and wouldn't it be great if you could register and have your own account, kinda like a
    photobucket layout, but with more file extensions and file hosting, if there is link me right
    away! It would be so awesome if they had unlimited image size and 5 minute video length. well
    what are your thoughts on this?....
  3. Need File Host
    (7)
    i require a host to host files that has a good upload speed (unlike megaupload, sendspace) it
    can't be filefront cuz i got banned for it not being game stuff. max file limit anythign over
    100mb ....
  4. Update Suggestions
    PHP and MySQL is outdated (2)
    I see that trap17 uses PHP 4.3.7 and MySQL 4.0.18. PHP 4.3.11 is out now, and so is MySQL 4.0.24.
    I'm not sure how or when the admins update the entire database, but I just wanted to inform
    everyone about this. Here are the links for the updates... http://www.php.net/downloads.php
    http://dev.mysql.com/downloads/mysql/4.0.html ....
  5. MySQL Datatbase Problem
    (2)
    I have seen alot of questions on the forums about how to back-up your mysql databases since the free
    hosting is going down. Even though some of you have been able to access cpanel (i still can on my
    old free hosting, stoneddevilinc.vaio-hosting.com) and are thinking the databases have been deleted,
    they have not. If you have read around about whats been going on, you would know that the Apache
    server program on the vaio-hosting server is down right now. Admin has been trying to fix it with no
    luck. MySQL and many other things, like your actual site, are not working si....
  6. Sig file problems
    (8)
    I have a signatue image I tried insert it using HTML -- BBCode EVERYTHING!! but it just
    displays my scripting-- What am i doing wrong? Pleas PM me -- Mike....
  7. Mysql Backup
    (8)
    Now that we know that free hosting will be gone, is there anyway that we can backup out Mysql
    databases? Thanks....
  8. File Urls?
    (5)
    I upload files to the public folder under a new folder now if I want to link these files to
    hyperlinks on my site I need each files url. How do I go about finding this? Would these files if
    zipped up become "downloadable" to my users?....
  9. Lost my mySQL databases
    (1)
    All of a sudden, today when I opened my site, I found I had lost both my mySQL databases
    /ohmy.gif' border='0' style='vertical-align:middle' alt='ohmy.gif' /> How did that happen??....
  10. Can I use mySQL of an other site ??
    (1)
    I want to have 2 DB (1 for backup, it's in an other site) while i modify DB on my site, it's also
    modify in backup site ! Please help me as soon as possible.....
  11. Do the paid service customers here have the mysql problem?
    (3)
    I am curious because I may want to go for the pay service instead of the free. Help me decide here
    on this issue. Do the paid service customers here have the mysql problem?....
  12. Connect to MySQL failed?
    (2)
    Connect to MySQL (localhost,zero8_zero8) failed my site URL is http://zero8.vaio-hosting.com
    why?....
  13. Loading values in txt file to database
    (0)
    I have a script that during the install, I am to run a file that is supposed to load zip code data
    into the database. It says it runs correctly at the end but yet the table in the database remains
    empty. Here is the code: PHP Code: CODE <? require('data.php');
    require('functions.php'); sql_connect();
    $file=file("admin/zip.txt"); $i=form_get("i"); $start=$i+1;
    $end=$start+5000; if($end>=count($file)){ $end=count($file);
    } for($i....
  14. HELP! MySQL Data base compleatly erased!!!
    (2)
    i went to my site to post a message saying I would be gone for about a week and the site was down,
    so I check on my MySQL data bases only it shows I have 0 Data bases :cry: :cry: :cry: :cry: :cry:
    :cry: Ironicaly enough I forgot for the first time EVER to back it up :cry: :cry: :cry: :cry:
    :cry: :cry: Luckly I've also had this problem on another host (though I had a back up) all that
    needed to happen whas the sql servers needed to be restarted is there any way possible to get them
    restarted? I tried also making a new DB but it wont work thats why I think they need t....
  15. Problem with MYSQL server
    (3)
    I have had this happen many times and i wanted to know a possible solution. Here is the error
    message: There seems to be a problem with the MySQL server, sorry for the inconvenience. We
    should be back shortly. the site URL is http://www.gtanation.vaio-hosting.com/ Thanks FNH
    for all of your help in the past though. (And that was serious, not sarcastically) Cody....
  16. Problem with the MySQL server
    (1)
    Hi, is this normal? im getting this message in my website, what's wrong? :? "There seems to be
    a problem with the MySQL server, sorry for the inconvenience. We should be back shortly." My
    website is http://www.ameba86.vaio-hosting.com Help Please!....
  17. MySQL down?
    (1)
    Is MySQL down? Or is it overloaded? I can't view it in cpanel either. Warning: mysql_connect():
    Too many connections ... I cannot connect to the database because: Too many connections....
  18. Why my MySql data base has ben deleted?
    (65)
    Why my MySql data base has ben deleted? seit: http://wiejski.vaio-hosting.com/index.php ....
  19. What files are you supposed to have under file manager?
    (3)
    Can someone tell me the files that are supposed to be under file manager...thanks!....
  20. mysql infos
    (2)
    hello... what are the infos for the mysql databases ? Like the host, is it localhost ? and the
    username ? And what does setting up users for the databases in cpanel does ? thanks in advance....
  21. Creating a settings file for your site (PHP)
    (0)
    Being a designer, sometimes it's easy to overlook the little things that you'll hate yourself for
    later on. For example, what if you change your domain name? Do you really want to change all 3254
    links on your site? Isn't there an easier way? Yes With a global settings file, you can
    avoid this altogether. Here's a template for creating such a file. CODE <?php
    /********************************************************** *      Functions, Variables, Ect for
    Revamp                                       * *           Author:  VampyreVein   ....
  22. MySql Tool
    (0)
    What are the best Open Source MySql developer tools?....
  23. html imput file
    (0)
    I would like to know if is possible to cange the file of the "html imput file" with source code
    Thanks....
  24. File size limit?
    (16)
    Is there a file size limit on the upload? Cause I'm trying to upload a file size of 1.97mb and
    everything it uploads at about 300kb it says QUOTE 421 Timeout (no new data for 900 seconds)
    Connection lost: vaio-hosting.com Transfer Failed! Anyhelp here?....
  25. Need: Public_html file...
    (2)
    I deleted it cuzz I thought I didn't need it :S Please someone send me it!!!....
  26. Setting Up Your MySQL & phpMyAdmin For The First Time
    (3)
    I have a very easy tutorial I have created, with screenshots too... Setting Up Your MySQL &
    phpMyAdmin For The First Time I have posted it as a link because there are so many images, and
    it saves on FNH bandwidth (See how considerate I am LOL).....
    http://matrixdesigns.info/modules.php?name...wtutorial&pid=1 ....
  27. what is the 'test' mysql table for?
    (3)
    just wondering... ^ thanks....
  28. Too Many Connections With Mysql...
    (3)
    Just in the morning.... CODE *** FATAL *** Cannot connect to localhost --- MySQL said:
    Too many connections Trouble has been reported to system administrator. Please try again later.
    Thank you. Oh...Trap17.So many men~oh.wish a more better server. /laugh.gif' border='0'
    style='vertical-align:middle' alt='laugh.gif' /> ....
  29. Which File Extension Are You?
    (48)
    Ever wonder which file extension you are? /smile.gif' border='0' style='vertical-align:middle'
    alt='smile.gif' /> Take the following test. http://bbspot.com/News/2004/10/extension_quiz.php as
    for me: i'm a PDF! /biggrin.gif' border='0' style='vertical-align:middle'
    alt='biggrin.gif' /> true, true. i have a certain attachment to PDFs. i collect PDF ebooks, and
    even my default printer is set to print in PDF! /biggrin.gif' border='0'
    style='vertical-align:middle' alt='biggrin.gif' /> any web page i want, i just press Ctrl-P, and
    voila -- a PDF co....
  30. 2 Gb Free For File Storage Or Web Hosting
    don't wait to see the link (12)
    here it is: CODE http://www.omnilect.com Omnilect is your own web storage, built on
    the idea that you should be able to keep all the data you share in one place and access it anywhere.
    The key features are: 2,000 Megabytes - Just For You. You need plenty of space - but it should be
    space you can actually use. Omnilect gives you 2,000 megabytes of storage and lets you use your
    space however you want - for email, photos, blogs, or whatever. We provide the services and the
    space, you provide the data. Best Email, Calendar, & Addressbook. Omnilect has the b....

    1. Looking for php, basics, mysql, file, commands

Searching Video's for php, basics, mysql, file, commands
advertisement



php tutorial - basics...up to mysql/file commands



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE