Course: Web Programming Code: 15CS52T Study Material
Course: Web Programming Code: 15CS52T Study Material
Study Material
Session No. 01
1. Open your browser and enter http://localhost/phpmyadmin. This will bring you
to the MYSQL setup page:
[Web Programming-15CS52T] 1
Department of Collegiate and Technical Education Diploma in CS&E
2. Enter a name for the database, then click on the create button. The name must
be 64 characters or less and composed of letters, numbers and underscores.
Avoid using numbers at the start of the name. A good name should indicate
the purpose of the database.
[Web Programming-15CS52T] 2
Department of Collegiate and Technical Education Diploma in CS&E
[Web Programming-15CS52T] 3
Department of Collegiate and Technical Education Diploma in CS&E
Example:
<? php
$new= htmlspecialchars (“<a href=’test’>Test</a>”);
echo $new;
?>
Output:
< a href=' test ' >Test < /a >
Another problem with special characters is when the PHP scripts get values through
GET, POST, or from Cookie. Strings from these sources could contain quotes, double
quotes, backslashes and null characters all of which could possibly cause problems.
To avoid these problems, PHP has an implicit backslashing function named
magic_quotes_gpc , which can be turned on or off in the PHP.ini file.
Magic quotes , is the process of escaping special characters with a ‘\’ to
allow a string to be entered into a database. If magic_quotes_gpc is turned on, you are
using all GET, POST and Cookies variables(gpc) in PHP will already have special
characters like “,’ and \ escaped so it is safe to put them directly into an SQL query.
[Web Programming-15CS52T] 4
Department of Collegiate and Technical Education Diploma in CS&E
When it is enabled state, all values received in a script from $_POST,$_GET and
$_COOKIE have backslashes implicitly inserted in front of all single quotes, double
quotes, backslashes and null characters.
For example, if the string
John said , It’s a beautiful day outside.
OUTPUT
John said , It\’s a beautiful day outside.
If the string John said, It’s a beautiful day outside is fetched from $_POST it would be
converted by magic_quotes_gpc to John said, It\’s a beautiful day outside.
But this conversion causes other problems. If the script compares the string with the
nonslashed version the comparison will fail. For example, if the query typed in a
textbox is:
Select * from address where name=’john’;
If the name of textbox is myquery, its value can be obtained as:
$query=$_POST[‘myquery’];
The value of $query is converted by magic_quotes_gpc() as:
Select * from address where name=\’john\’;
But this string is not a legal SQL command because of backslashes. If it is sent to
MySQL as a command, it will reject it and displays an error.
To accept SQL command through forms, we have to remove the escaping that magic
quotes puts in. To do this, we have two options :disable magic quotes or strip the
backslashes.
The backslashes can be stripped of using stripslashes() function.
Example:
<? php
$str= “It\’s time to learn PHP”;
echo stripslashes($str);
?>
OUTPUT
It’s time to learn PHP
[Web Programming-15CS52T] 5