Jump to content
xisto Community

Archimedes

Members
  • Content Count

    7
  • Joined

  • Last visited

Everything posted by Archimedes

  1. Well, the last lesson was on If...Else statements, this one will be on Functions. Things you need to know 1.Basic PHP(Lesson 1) 2.I only speak English, sorry. So, everything will be in English terms. 3.I only put the stuff in quotes to be more organized. xD Lesson #3; Functions! Questions & Answers Q1.What is a function? A1.A function is code that we can access at any time, such as the e-mail function; mailto(email@something.com). Q2.Why use functions? A2.Would you rather use <?phplots and lots of codemore codemore and more code?>or function()? Making functions 1.To create a function, simple type function function_name() { what it does; } 2.Say I wanted to make a function that says "Xisto is the best host ever deal with it!", and named Xisto(), it would look like this. <?phpfunction Xisto() { echo "Xisto is the best host ever deal with it!"; }Xisto();?>[b]Output:[/b]Xisto is the best host ever deal with it!3.That was a fairly simple function, let's move onto something a bit more, not so simple.[/quote][quote][b]More complex functions[/b]1.Can have If...Else statements in it.2.Making a function say different things.[code]<html><body><?phpfunction host($abc) { echo $abc . " is a great web host!<br />"; }host("Xisto");host("Xisto");-host("Xisto - Web Hosting");?></body></html> Output:Xisto is a great web host! Xisto is a great web host! Xisto - Web Hosting is a great web host!
  2. Alright, this is part #2 of my PHP Lessons. We will go into depth with more of the, scripting part of PHP. Things you should know. 1. Basic PHP 2. Understanding of scripting. If...Else statements 1. If...Else statements are used if you want your script/scripts to do something based on a variable. <?phpif (condition)code to be done if condition is true;elsecode to be done if condition is false;?>2. With that, you're probably a bit still confused as to what it's doing, I was too at first. Look at the next code for a better explanation. This is if there was a form prior to this page, that form, asking what is 4+5, their answer being $a. <?php$a = 4+5;if($a == 9)echo "You are correct, 4+5=9!";elseecho "You are not correct, please go back and try again.";?>3. If the persons answer is 9, the page will say 'You are correct, 4+5=9!', if not, it will say 'You are not correct, please go back and try again.'4. Now, the If...elseif...else statement. <?php$d=date("D");if ($d=="Fri") echo "Have a nice weekend!"; elseif ($d=="Mon") echo "Have a nice week!"; else echo "Have a nice day!"; ?>5. If the day is Friday, it says 'Have a nice weekend!', if the day is Monday, it will say 'Have a nice week!', and if the day is not Friday or Monday, it says 'Have a nice day!'. That's it for If...Else statements, next lesson would be on Arrays, but I don't like Arrays so it'll be made later on, next Lesson will be on functions.
  3. CroNous is a wonderful MMO! Reasons to play. 1. It's free! 2. It's a server based game, no more boring flash games. 3. Free unlike WoW. All you do is go to CroNous. Download it. And play. Leave your replies. My stuff. Server: Lapis Channel: Ch 2 PvP. Current name: MedesArchi. Current main's Class:Magician. Enjoy. The Human Calculator, Archimedes
  4. Notice from Yordan: copied from w3schools.com under php section pages 1,3,4
  5. Thank you, Yordan, I plan to have many more tutorials in the future! xD
  6. Alright, some of you might want to display your User's or Members on your site. Notes: 1.This is to fit in with Feelay's register and Log-in scripts you can find in the tutorial section. 2.I made this to show the members of my site who is a member and what their ID is. First off, we must set up a connection to our MySQL Database. <?php$con = mysql_connect("localhost","database_username","database_username_password");if (!$con) { die('Could not connect: ' . mysql_error()); } What it does:1.It is starting a PHP document. 2.Next it sets up a connection to the database with the members table. 3.Change 'database_username' to your database username. 4.Change 'database_username_password' to your username's password. Next, we select the database the information is stored at using the 'mysql_select_db() function. mysql_select_db("userbase_name", $con); What it does:1.All it is doing is selecting a database using the connection in the first part of code. For the next part, we will be selecting the table in which the members info is stored at, whereas the table is named 'members'. And you want to order them by ID. $result = mysql_query("SELECT * FROM members ORDER BY ID"); What it does:1.The '$result', is just a variable, so you don't have to type the function again. 2.It is selecting everything '*', from the table members and ordering it by the user's ID. For the third part, we will be creating a HTML table to display the user information. echo "<table border='0'><tr><th>UserName</th><th>ID</th></tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['UserName'] . "</td>"; echo "<td>" . $row['ID'] . "</td>"; echo "</tr>"; }echo "</table>"; What it does:1.You can can change the '0' in the <table border=''> tag to anything you chose. 2.The '<th>User Name</th>'&'<th>ID</th>' tags are the top of the table. 3.The 'while() function is creating an array, whereas '$row' is a variable to shorten your work, instead of typing the mysql_fetch_array() function out again. 4.The 'echo "<td>" . $row['UserName'] . "</td>";' & ' echo "<td>" . $row['ID'] . "</td>";' is just selecting the info from the table to be displayed, whereas the user/members name is stored in the column 'UserName' and the ID is stored under 'ID'. Ending your document. mysql_close($con);?> What it does:1.It is closing the connection we made in the first part of this tutorial. 2.It is closing the <?php tag in the first part of code of this tutorial. The Output User Name ID User1 1 User2 2 User3 3 User4 4 etc. etc. That's it! Any questions, feel free to ask. This is my first tutorial on Xisto forums.
  7. In the regcheck.php document, you forgot some of the echo commands. Line 16; "Username And Password Can Not Be The Same.";Should be;echo "Username And Password Can Not Be The Same."; Line 42;"You Are Registered And Can Now Login";Should be;echo "You Are Registered And Can Now Login"; Line 50;"The Username You Have Chosen Is Already Being Used By Another User. Please Try Another One.";Should be;echo "The Username You Have Chosen Is Already Being Used By Another User. Please Try Another One."; Line 57; "You Could Not Be Registered Because Of Missing Data.";Should be;echo "You Could Not Be Registered Because Of Missing Data."; Other than that, nice job.
×
×
  • 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.