Description: Learn how to use MySQL syntax with these references.
AND: This will do our command to two or more settings, I think reading the code will explain more than I can try to in normal English…
INSERT: Inserts a new row into an existing table of your database with the values you define for each field. Used in conjunction with mysql_connect() mysql_select_db() mysql_query()
ALTER: ALTER will change the table you specify, see the code example for a more clear idea of how it works…
NOT: This will SELECT all records from the db table WHERE ’something’ is NOT equal to ‘whatever’.
OR: The OR command will SELECT either one or the other… (again it is easier to look at the code to make sense of it.)
ORDER BY: Using ORDER BY will sort the results in a specific order based on the values of the desired column: see the example for more details…
CREATE TABLE: Using CREATE TABLE will do exactly that – create a new sql table in your database. See the example code for the syntax, each column you define also has to have a column data-type, this can be ‘text’, ‘char’, ‘blob’ amongst many, many
SELECT: The SELECT statement will select ’something’ FROM ’sometable’.
UPDATE: Using UPDATE will update a specified record with a new value. Or record in the db table.
DELETE: Using DELETE will remove (delete, even!) the record (row in the table) from the database. Usually used with a WHERE clause to restrict the deletion to a certain record or set of records.
WHERE: Used in conjuction with a SELECT statement, using WHERE will restrict the SELECT to a certain rule…
In general when a new software version appears everybody hurries to update it particularly if it is for free. PHP 5 has just come into view and it seems that there are people who use the PHP 4 version and others who use the PHP 5 one.
You most likely know that PHP 5 is destined for OOP, but it appears that usual programming can be used too. Furthermore, OOP is used in PHP4 as well, with the difference that in PHP5 things are a little more evaluated. This means that in PHP4 safety modes for classes (public, private) are not accepted. In PHP4 the objects are a kind of structures which accept objects and functions as well, according to OOP. In PHP4 they are useful as well.
If you are used to working with PHP4 you can use PHP5 with no problems because the differences are not important and the changes were made so that programmers would not be confused. An example would be class builders which, in PHP4 were functions within the classes bearing the same name as the class. In PHP5 it is firstly checked if there is a function (method) __construct (). If it does not exist, check if there is a function (method) which has the same name as the class. This means that even if you are not aware of the latest news in the domain of PHP5, your scripts will function without any problem.
If you want to install PHP4 and PHP5 in parallel, you can set USE indicators, which are different for each version and you can find out a lot of other important pieces of information asking us.
During work with any language we make use of variables. Variables are used to store values and reuse them in our code. We use different types of variables in our code such as strings (text), integers (numbers), floats (decimal numbers), Boolean (true or false) and objects. In PHP we can make use of variable while writing scripts. In this lesson we’re going to cover PHP variables.
PHP Variable Syntax
$var_name = value;
Important Variable in PHP?
Some key points to notice:
(1) Remember to put the $ sign in front of variables when declaring variables in PHP.
(2)Variable names must start with letters or underscore.
(3) Variables can’t include characters except letters, numbers or underscore.
What is a variable?
A variable is a indicate to store values such as strings, integers or decimals so we can easily reuse those values in our code. For example, we can store a string value such as “Hello world” or an integer value of 100 into a variable.
PHP variable types?
Different Java or C++, PHP doesn’t care about primitive types. Any variable, a string, an integer or a float is declared the same way. PHP converts the types in the code by itself. Here’s what I mean.
//an integer variable $var_name = 300;
//an float variable $var_name = 300.00 ?>
PHP Variable type manage
Like talk about above, PHP doesn’t require variables to declared using primitive types. Therefore, manage between two types doesn’t require use of any special function. We can simply do things like…
//string var $var = “0″;
//var is now float $var += 8.5;
//var is now integer $var += 3;
//var is now string $var .= ” is the sum”; echo $var;
?>
Concatenating variables in PHP?
In PHP we can join two variables by using the dot ‘.’ operator.
$var1 = “Hello world”; $var2 = “and Java”;
//prints “Hello world and Java” echo $var1 . $var2;
$var1 = “1″; $var2 = “2″;
//prints “12″; echo $var1 . $var2;
?>
So there you have it, a quick and easy variable lesson in PHP.
Javascript can be used with PHP without problems, as long as you keep in mind that they operate in different environments (see Frames, JavaScript, and PHP Overview):
PHP, is server side. Therefore, if you want to pass data from a form to PHP, you have to submit it and load the page again. There is no getting about it.
Javascript is client side (run in the browser), and can help you with dynamic functionality. You can easily use JavaScript and PHP jointly. However, just like PHP knows nothing about Javascript. PHP will just echo the Javascript code to the HTML page, just as it would echo the value of a string variable.
EXAMPLE
<?php
echo ‘Welcome to PHP’;
?>
and
<?php
echo ‘<script type=”text/javascript”>
<!–
if ( 1 ) {
window.open(\’any.php?name=News\’, \’hello world\’,
\’HEIGHT=500, resizable=yes, WIDTH=500\’);
}
//–>
</script>’;
?>
They both echo strings, of which the first one is simply displayed in the client’s browser as a welcome message, while the second one is take by the client’s browser and leads to the browser sending a request for the News module, which in turn sends the usual home page of a PHP site to be displayed on the client.
With this in brain, Javascript does not demand any special treatment when used in PHP blocks. Just append the Javascript code to the $content variable of the block and you are done. Of course, you have to escape double quotes – and it is a good idea to add a newline (\n) to the end of each Javascript line (see Javascript and BLOCKs).
If you use sed, the following sequence of set commands, applied to a Javascript file, will produce the right PHP code to include in the PHP block:
(A) 1,$s/”/\\”/g
(B) 1,$s/^/\$content \.= “/
(C) 1,$s/$/”;/
(D) 1,$s/”;$/\\n”;/
A Escape all double quotes.
B. Add a newline \n at the end of each JS line
C Add the string ‘”;’ at the end of every line.
D. Add the string ‘$content .= “‘ at the start of every line
The $_POST variable is used to collect values from a form with method=”post”. Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.
The $_POST variable is used to collect values from a form with method=”post”.
The $_POST variable is an array of variable names and values sent by the HTTP POST method.
Example
<form action=”chi1.php” method=”post”>
Enter your name: <input type=”text” name=”name” />
Enter your Dob: <input type=”text” name=”Dob” />
<input type=”OK” />
</form>
The “chi1.php” file can now use the $_POST variable to catch the form data (notice that the names of the form fields will automatically be the ID keys in the $_POST array):
hi <?php echo $_POST["name"]; ?>.<br />
your <?php echo $_POST["Dob"]; ?> how old!
Why make use of $_POST?
A Variables have no length limit
B Variables sent with HTTP POST are not shown in the URL
yet, because the variables are not displayed in the URL, it is not possible to bookmark the page.
The $_REQUEST Variable
The PHP $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE.
The PHP $_REQUEST variable can be used to get the result from form data sent with both the GET and POST methods.
Example
hi <?php echo $_REQUEST["name"]; ?>.<br />
your <?php echo $_REQUEST["Dob"]; ?> how old!