!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!PHP - Code !!!! 26.07.2013 1!!!21.08.2013
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!PHP - Code !!!! 26.07.2013 1!!!21.08.2013
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!PHP - Code !!!! 26.07.2013 1!!!21.08.2013
2013
1. Konekcija na bazu.
<?php
$host="localhost";
$uname="root";
$pass="";
$connection= mysql_connect ($host, $uname, $pass);
if (!$connection) {
die ("A connection to the server could not be established!");
}
$result=mysql_select_db ("faks");
if (! $result) {
die ("database could not be selected");
}
echo "Database spremna za koritenje.";
?>
2. Konekcija na server.
<?php
$host="localhost";
$uname="root";
$pass="";
$connection= mysql_connect ($host, $uname, $pass);
if (! $connection) {
die ("A connection to the Server could not be established!");
} else {
echo "Korisnik se logirao na server ",$host," Spreman.";
}
?>
3. Konekcija na bazu.
<?php
@mysql_connect("localhost","root","") or die("Could not connect to MySQL
server!");
@mysql_select_db("faks") or die("Could not select database!");
echo "Vi ste spojeni na MySQL bazu podataka!";
mysql_close();
?>
4. Brisanje slogova u bazi preko ID-a
<html>
<body>
<?php
$cnx = mysql_connect('localhost','root','');
mysql_select_db('faks');
$id = '3';
6. Listing baza
<html>
<head>
<title>Listing the databases available in a connection</title>
</head>
<body>
<?php
$user = "root";
$pass = "";
$link = mysql_connect( "localhost", $user, $pass );
if ( ! $link )
die( "Couldn't connect to MySQL" );
$db_res = mysql_list_dbs( $link );
$num = mysql_num_rows( $db_res );
for( $x = 0; $x < $num; $x++ )
print mysql_tablename( $db_res, $x )."<br>";
mysql_close( $link );
?>
</body>
</html>
8. Multipli konekcija
<?php
$link1 = @mysql_connect("localhost", "root", "") or die("Could not
connect to MySQL server!");
//$link2 = @mysql_connect("edukat.org", "edukat", "sdf65ezdfg") or
die("Could not connect to MySQL server edukat!");
?>
9. Listanje procesa
<?php
mysql_connect("localhost","root","");
$processes = mysql_list_processes();
echo "<table>";
echo "<tr><th>ID</th><th>User</th><th>Host</th><th>DB</th>
<th>Command</th><th>Time</th><th>State</th><th>Info</th>
</tr>";
while ($row = mysql_fetch_row($processes)) {
list($id,$user,$host,$db,$command,$time,$state,$info) = $row;
echo "<tr><td>$id</td><td>$user</td>
<td>$host</td><td>$db</td><td>$command</td>
<td>$time</td><td>$state</td><td>$info</td>
</tr>";
}
echo "</table>";
?>
10.
Uitavanje zapisa
<?php
@mysql_connect("localhost", "root","") or die("Could not connect to MySQL
server!");
@mysql_select_db("faks") or die("Could not select database!");
$query = "UPDATE studenti SET title =\"BBB\" WHERE id = 1";
$result = mysql_query($query);
print "Total row updated: ".mysql_affected_rows();
mysql_close();
?>
11.
Zatvaranje baze
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("faks");
mysql_close( );
?>
12.
Konekcija na bazu
<?php
@mysql_connect("localhost", "root", "") or die("Could not connect to MySQL
server!");
@mysql_select_db("faks") or die("Could not select company database!");
print "You're connected to a MySQL database!";
mysql_close();
?>
13.
<?php
function opendatabase ($host,$user,$pass) {
try {
if ($db = mysql_connect ($host,$user,$pass)){
return $db;
} else {
throw new exception ("Sorry, could not connect to mysql.");
}
} catch (exception $e) {
echo $e->getmessage ();
}
}
function closedatabase ($db){
mysql_close ($db);
}
$db = opendatabase ("localhost","root","");
try {
if (!mysql_select_db ("faks",$db)){
throw new exception ("Sorry, database could not be opened.");
}
$myquery = "INSERT INTO studenti (ime,prezime,indeks) VALUES
('Reed','Blue',300)";
if (mysql_query ($myquery, $db)){
echo "We were successful.";
} else {
throw new exception (mysql_error());
}
} catch (exception $e) {
echo $e->getmessage();
}
closedatabase ($db);
?>
14.
Konekcija na bazu
<?php
try {
$mysqlhost = "localhost";
$mysqluser = "root";
$mysqlpass = "";
if ($db = mysql_connect ($mysqlhost,$mysqluser,$mysqlpass)){
echo "Successfully connected to the database.";
mysql_close ($db);
} else {
throw new exception ("Sorry, could not connect to mysql.");
}
} catch (exception $e) {
echo $e->getmessage ();
}
?>
15.
<?php
$domain = "localhost";
$user = "root";
$password = "";
$conn = mysql_connect( $domain, $user, $password );
if($conn)
{
$msg = "Congratulations $user, You connected to MySQL";
}
?>
<html>
<head>
<title>Connecting user</title>
</head>
<body>
<h3>
<?php echo( $msg ); ?>
</h3>
</body>
</html>
16.
<html>
<head>
<title>Opening a Connection to a Database</title>
</head>
<body>
<div>
<?php
$user = "root";
$pass = "";
$db = "faks";
$link = @mysql_connect( "localhost", $user, $pass );
if ( ! $link ) {
die( "Couldn't connect to MySQL: ".mysql_error() );
}
print "<h2>Successfully connected to server</h2>\n\n";
@mysql_select_db( $db )
or die ( "Couldn't open $db: ".mysql_error() );
print "Successfully selected database \"$db\"<br />\n";
mysql_close( $link );
?>
</div>
</body>
</html>
17.
Printanje podataka
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("faks");
$result = mysql_query("SELECT * FROM studenti");
while($row = mysql_fetch_array($result)) {
foreach($row as $key=>$value) {
echo "$key = $value<BR/>\n";
}
?>
mysql_free_result($result);
mysql_close();
18.
<html>
<head>
<title>Get data</title>
</head>
<body>
<?php
$conn = @mysql_connect( "localhost", "root", "" ) or die( "Err:Conn" );
or die( "Err:Db" );
<html>
<head>
<title>Get data</title>
</head>
<body>
<?php
$conn=@mysql_connect( "localhost", "root", "" ) or die( "Err:Conn" );
$rs = @mysql_select_db( "faks", $conn ) or die( "Err:Db" );
$sql = "select id, ime from studenti";
$rs = mysql_query( $sql, $conn );
while( $row = mysql_fetch_array( $rs ) )
{
echo( "ID: " . $row["id"] );
echo( " - Ime: " . $row["ime"] . "<br>" );
}
?>
</body>
</html>
20. Printanje jednog polja 2
<?php
mysql_connect("localhost","root","");
mysql_select_db("faks");
$query = "SELECT id, prezime FROM studenti ORDER BY prezime";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
$prezime = $row[1];
$id = $row[0];
echo "Prezime: $prezime ($id) <br />";
}
?>
21.
<?php
mysql_connect("localhost","root","");
mysql_select_db("faks");
$query = "SELECT indeks, prezime FROM studenti ORDER BY prezime";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$prezime = $row['prezime'];
$indeks = $row['indeks'];
echo "Naziv: $prezime ($indeks) <br />";
}
?>
22.
Timestamp
<html>
<head>
<title>Using timestamp</title>
</head>
<body>
<?php
error_reporting(0);
$conn = mysql_connect( "localhost", "root", "" );
$rs = mysql_select_db( "faks", $conn );
$sql = "select * from studenti where id=2";
$rs = mysql_query( $sql, $conn );
#split the timestamp into organized date format
while ( $row = mysql_fetch_array( $rs ) )
{
$datetime = $row["time"];
$year = substr( $datetime, 0, 4 );
$mon = substr( $datetime, 4, 2 );
$day = substr( $datetime, 6, 2 );
$hour = substr( $datetime, 8, 2 );
$min = substr( $datetime, 10, 2 );
$sec = substr( $datetime, 12, 2 );
$orgdate = date("l F dS, Y h:i A", mktime( $hour, $min, $sec, $mon,
$day, $year ) );
echo( "Time of entry: " . $orgdate );
}
?>
</body>
</html>
23.
<?php
function opendatabase ($host,$user,$pass) {
try {
if ($db = mysql_connect ($host,$user,$pass)){
return $db;
} else {
throw new exception ("Sorry, could not connect to mysql.");
}
} catch (exception $e) {
echo $e->getmessage ();
}
}
function selectdb ($whichdb, $db){
try {
if (!mysql_select_db ($whichdb,$db)){
throw new exception ("Sorry, database could not be opened.");
}
} catch (exception $e) {
echo $e->getmessage();
}
}
function closedatabase ($db){
mysql_close ($db);
}
$db = opendatabase ("localhost","root","");
selectdb ("faks",$db);
if ($aquery = mysql_query ("SELECT * FROM studenti ORDER BY id ASC")){
while ($adata = mysql_fetch_array ($aquery)){
echo "ID: " . $adata['id'] . "<br />";
echo "Ime: " . stripslashes ($adata['ime']) . "<br />";
echo "Prezime: " . stripslashes ($adata['prezime']) . "<br />";
}
} else {
echo mysql_error();
}
closedatabase ($db);
?>
24.
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("faks");
$result = mysql_query("SELECT * FROM studenti");
if ($result && mysql_num_rows($result)) {
$numrows = mysql_num_rows($result);
$rowcount = 1;
print "There are $numrows people in tabeli studenti:<br
/><br />";
}
?>
25.
<?php
mysql_connect("localhost","root","");
mysql_select_db("faks");
$query = "SELECT * FROM studenti LIMIT 1";
$result = mysql_query($query);
$fields = mysql_num_fields($result);
for($count=0;$count<$fields;$count++)
{
$field = mysql_fetch_field($result,$count);
echo "<p>$field->name $field->type ($field->max_length)</p>";
}
?>
26.
<?php
@mysql_connect("localhost", "root","") or die("Could not connect to MySQL
server!");
@mysql_select_db("faks") or die("Could not select database!");
$query = "SELECT * FROM studenti";
$result = mysql_query($query);
print "<table>\n";
print "<tr>\n<th>id</th><th>ime</th><th>prezime</th>\n</tr>\n";
while (list($id, $ime, $prezime) = mysql_fetch_row($result)) :
print "<tr>\n";
print "<td>$id</td>\n<td>$ime</td>\n<td>$prezime</td>\n";
print "</tr>\n";
endwhile;
print "</table>";
mysql_close();
?>
27.
<?php
mysql_connect("localhost","root","");
mysql_select_db("faks");
$query = "SELECT id, prezime FROM studenti ORDER BY prezime";
$result = mysql_query($query);
while (list($id, $prezime) = mysql_fetch_row($result))
{
}
28.
Tip polja
<?php
mysql_connect("localhost","root","");
mysql_select_db("faks");
$query = "SELECT id as ID, prezime FROM studenti ORDER BY prezime";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
echo mysql_field_type($result, 0);
?>
29.
<html>
<head>
<title>Selecting Data</title>
</head>
<body>
<?php
$user = "root";
$pass = "";
$db = "faks";
$link = mysql_connect( "localhost", $user, $pass );
if ( ! $link ) {
die( "Couldn't connect to MySQL: ".mysql_error() );
}
mysql_select_db( $db, $link ) or die ( "Couldn't open $db:
".mysql_error() );
@mysql_select_db("faks") or die("Could not select database!");
$query = "SELECT * FROM studenti";
$result = mysql_query( "SELECT * FROM studenti " );
$num_rows = mysql_num_rows( $result );
print "<p>$num_rows je dodano u tabelu</p>\n";
print "<table>";
while ( $a_row = mysql_fetch_row( $result ) ) {
print "<tr>";
foreach ( $a_row as $field ) {
print "<td>".stripslashes($field)."</td>";
}
print "</tr>";
}
print "</table>";
mysql_close( $link );
?>
</body>
</html>
30.
Konekcija na bazu
<?php
try {
$mysqlhost = "localhost";
$mysqluser = "root";
$mysqlpass = "";
if ($db = mysql_connect ($mysqlhost,$mysqluser,$mysqlpass)){
echo "Successfully connected to the database.";
mysql_close ($db);
} else {
throw new exception ("Sorry, could not connect to mysql.");
}
} catch (exception $e) {
echo $e->getmessage ();
}
?>
31.
Konekcija korisnika
<?php
$domain = "localhost";
$user = "root";
$password = "";
$conn = mysql_connect( $domain, $user, $password );
if($conn)
{
$msg = "Congratulations $user, You connected to MySQL";
}
?>
<html>
<head>
<title>Connecting user</title>
</head>
<body>
<h3>
<?php echo( $msg ); ?>
</h3>
</body>
</html>
32.
Konekcija na server
<html>
<head>
<title>Opening a Connection to a Database</title>
</head>
<body>
<div>
<?php
$user = "root";
$pass = "";
$db = "faks";
$link = @mysql_connect( "localhost", $user, $pass );
if ( ! $link ) {
die( "Couldn't connect to MySQL: ".mysql_error() );
}
print "<h2>Successfully connected to server</h2>\n\n";
@mysql_select_db( $db )
or die ( "Couldn't open $db: ".mysql_error() );
print "Successfully selected database \"$db\"<br />\n";
mysql_close( $link );
?>
</div>
</body>
</html>
33.
<html>
<head>
<title>Adding a Row to a Database</title>
</head>
<body>
<div>
<?php
$user = "root";
$pass = "";
$db = "bod";
$link = @mysql_connect( "localhost", $user, $pass );
if ( ! $link ) {
die( "Couldn't connect to MySQL: ".mysql_error() );
}
print "<h2>Successfully connected to server</h2>\n\n";
@mysql_select_db( $db ) or die ( "Couldn't open $db: ".mysql_error() );
print "Successfully selected database \"$db\"<br />\n";
$query = "INSERT INTO bodovi( student, predmet, profesor )values( 'alija
bobija', 'informatika', 'meda' )";
print "running query: <br />\n$query<br />\n";
mysql_query( $query, $link ) or die ( "INSERT error: ".mysql_error() );
mysql_close( $link );
?>
</div>
</body>
</html>
34.
<?php
function opendatabase ($host,$user,$pass) {
try {
if ($db = mysql_connect ($host,$user,$pass)){
return $db;
} else {
throw new exception ("Sorry, could not connect to mysql.");
}
} catch (exception $e) {
echo $e->getmessage ();
}
}
Quest_book
<html>
<head>
<title>Sign the guestbook</title>
</head>
<body>
<?php
error_reporting(0);
$self = $_SERVER['PHP_SELF'];
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$submit = $_POST['submit'];
$form = "<form action=\"$self\" method=\"post\">";
$form.=
$form.=
$form.=
$form.=
$form.=
$form.=
$form.=
$form.=
$form.=
Login
<?php
function opendatabase ($host,$user,$pass) {
try {
if ($db = mysql_connect ($host,$user,$pass)){
return $db;
} else {
throw new exception ("Sorry, could not connect to mysql.");
}
} catch (exception $e) {
echo $e->getmessage ();
}
}
37.
<?php
error_reporting(0);
$user = "root";
$pass = "";
$db = "faks";
$link = @mysql_connect( "localhost", $user, $pass );
if ( ! $link ) {
die( "Couldn't connect to MySQL: ".mysql_error() );
}
print "<h2>Successfully connected to server</h2>\n\n";
@mysql_select_db( $db ) or die ( "Couldn't open $db: ".mysql_error() );
print "Successfully selected database \"$db\"<br />\n";
?>
38.
<?php
$domain = "localhost";
$user = "root";
$password = "";
$conn = mysql_connect( $domain, $user, $password );
if($conn)
{
$msg = "Congratulations $user, You connected to MySQL";
}
?>
<html>
<head>
<title>Connecting user</title>
</head>
<body>
<h3>
<?php echo( $msg ); ?>
</h3>
</body>
</html>
39.
Status baze
<?php
mysql_connect("localhost","root","");
$status = explode(' ', mysql_stat());
foreach($status as $value) echo $value."<br />";
?>
40.
Lista databazi
<?php
error_reporting(0);
<?php
error_reporting(0);
?>
mysql_connect("localhost","root","");
$tables = mysql_list_tables("bod");
$count = 0;
while ($count < mysql_numrows($tables))
{
echo mysql_tablename($tables,$count)."<br />";
$count++;
}
42.
<?php
$mysqli = new mysqli("localhost", "root", "","faks", 3306);
$queries = "SELECT * FROM studenti; SELECT * FROM predmeti";
if(mysqli_multi_query($mysqli, $queries)) {
do {
if($result = mysqli_store_result($mysqli)) {
while($row = mysqli_fetch_row($result)) {
foreach($row as $key => $value) {
echo "$key => $value<BR/>\n";
}
}
mysqli_free_result($result);
}
if(mysqli_more_results($mysqli)) {
<?php
$mysqli = new mysqli("localhost", "root","", "faks");
$query = "SELECT id, ime, prezime, indeks FROM studenti ORDER BY id";
$stmt = $mysqli->prepare($query);
$stmt->execute();
$stmt->bind_result($id, $ime, $prezime, $indeks);
while($stmt->fetch()) {
echo "$id, $ime, $prezime, $indeks <br />";
}
$stmt->close();
$mysqli->close();
?>
44.
Ispis tabele
<?php
$mysqli = new mysqli ("localhost","root","","faks");
try {
if (mysqli_connect_errno()){
throw new exception ("Error: " . mysqli_connect_errno() . " - ".
mysqli_connect_error());
} else {
if ($cdquery = $mysqli->query ("SELECT * FROM studenti ORDER BY id
ASC")){
/>";
$prep->execute();
echo $prep->affected_rows . " row(s) affected.";
$prep->close();
if ($result = $mysqli->prepare ("SELECT ime, prezime FROM studenti
WHERE id > 2")){
$result->execute ();
$result->bind_result ($ime,$prezime);
while ($result->fetch ()){
echo "ime: " . stripslashes ($ime) . "<br />";
echo "prezime: " . stripslashes ($prezime) . "<br />";
}
$result->close ();
} else {
echo $mysqli->errno . " - " . $mysqli->error;
}
$mysqli->close();
}
} catch (exception $e) {
echo $e->getmessage();
}
?>
Ispis tabele
45.
<?php
Ispis tabele
<?php
$mysqli = new mysqli("localhost", "root", "","faks", 3306);
$query = "SELECT id, ime, prezime FROM studenti ORDER BY ime";
$result = $mysqli->query($query);
while ($row = $result->fetch_array(MYSQLI_NUM))
{
$id = $row[0];
$ime = $row[1];
$prezime = $row[2];
?>
47.
Ispis tabele
<?php
$mysqli = mysqli_connect("localhost", "root", "", "faks");
<html>
<head>
<title>Opening a Connection to a Database</title>
</head>
<body>
<div>
<?php
$user = "root";
$pass = "";
$db = "faks";
$link = @mysql_connect( "localhost", $user, $pass );
if ( ! $link ) {
die( "Couldn't connect to MySQL: ".mysql_error() );
}
print "<h2>Successfully connected to server</h2>\n\n";
@mysql_select_db( $db )
or die ( "Couldn't open $db: ".mysql_error() );
print "Successfully selected database \"$db\"<br />\n";
mysql_close( $link );
?>
</div>
</body>
</html>
49.
<?php
$mysqli = mysqli_connect("localhost", "root", "","faks", 3306);
$result = mysqli_query($mysqli, "SELECT * FROM studenti");
while($row = mysqli_fetch_array($result)) {
Funkcija instaliranje
<?php
function mysqlinstalled (){
if (function_exists ("mysql_connect")){
return true;
} else {
return false;
}
}
function mysqliinstalled (){
if (function_exists ("mysqli_connect")){
return true;
} else {
return false;
}
}
if (mysqlinstalled()){
echo "<p>The mysql extension is installed.</p>";
} else {
echo "<p>The mysql extension is not installed..</p>";
}
if (mysqliinstalled()){
echo "<p>The mysqli extension is installed.</p>";
} else {
echo "<p>The mysqli extension is not installed..</p>";
}
?>
51.
<html>
<head>
<title>MySQL Connection Test</title>
</head>
<body>
<h2>
<?php $connection = mysql_connect( "localhost", "root", "" )
or die( "Sorry - unable to connect to MySQL" );
echo( "Congratulations - you connected to MySQL" );
?>
</h2>
</body>
</html>
52.
Ispisivanje kreke
<?php
$link = mysqli_connect("localhost", "root", "", "faks");
if(!$link) {
$mysql_error = "Connection error: ".mysqli_connect_error();
die($mysql_error);
}
$result = mysqli_query($link, "SELECT * FROM foo");
if(!$result) {
$errno = mysqli_errno($link);
$error = mysqli_error($link);
die("Query Error: $error (code: $errno)");
}
?>
53.
Ispis sloga
<?php
@mysql_connect("localhost", "root","") or die("Could not connect to MySQL
server!");
@mysql_select_db("faks") or die("Could not select database!");
$query = "SELECT * FROM studenti";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) :
print $row["id"];
endwhile;
mysql_close();
?>
54.
<?php
$mysqli = mysqli_connect("localhost", "root", "", "faks");
if(mysqli_connect_errno()) {
die("Could not connect: ".mysqli_connect_error());
}
$query = "SELECT ime, prezime, indeks FROM studenti WHERE ime LIKE
'meda'";
$stmt = mysqli_prepare($mysqli, $query);
mysqli_execute($stmt);
mysqli_stmt_bind_result($stmt, $ime, $prezime, $indeks);
while(($res = mysqli_stmt_fetch($stmt))) {
echo "Ime: $ime<BR/>\n";
echo "Prezime: $prezime<BR/>\n";
echo "Indeks: $indeks<BR/>\n";
}
if($res === false) {
die("An error occurred fetching: ".mysqli_error($mysqli));
}
mysqli_stmt_close($stmt);
mysqli_close($mysqli);
?>
55.
Konektovanje ODBC
<?php
$connect = @odbc_connect("myAccessDB", "root", "") or die("Could not
connect to ODBC database!");
print "Currently connected to ODBC database!";
odbc_close($connect);
?>
56.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Explore Wines in a Region</title>
</head>
<body bgcolor="white">
<form action="example.6-11.php" method="GET">
<br>Enter a region to browse :
<input type="text" name="regionName" value="All">
(type All to see all regions)
<br><input type="submit" value="Show wines">
</form>
<br><a href="index.html">Home</a>
</body>
</html>
58.
Pretraivanje
<html>
<head>
<title>Searching for a student...</title>
</head>
<body bgcolor=#ffffff>
<h2>Search</h2>
<form name="search" method="post" action="studentsearch-exec.php">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="firstname">First Name</option>
<Option VALUE="lastname">Last Name</option>
<Option VALUE="idnumber">ID Number</option>
</Select>
<input type="submit" name="search" value="Search" />
</form>
</body>
</html>
59.
itanje reda
Combo box
<?php
if (isset($_POST['submit'])) {
$rowID = $_POST['id'];
mysql_connect("localhost","root","");
mysql_select_db("faks");
$query = "SELECT * FROM studenti WHERE ID='$id'";
$result = mysql_query($query);
list($id,$ime,$prezime,$indeks) = mysql_fetch_row($result);
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<select prezime="id">
<option prezime="">Choose a studenti:</option>
<option prezime="1">1</option>
<option prezime="2">2</option>
<option prezime="3">3</option>
</select>
<input type="submit" prezime="submit" value="Submit" />
</form>
61.
<html>
<head>
<title>Searching for a student...</title>
</head>
<body bgcolor=#ffffff>
<h2>Search</h2>
<form name="search" method="post" action="studentsearch-exec.php">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="firstname">First Name</option>
<Option VALUE="lastname">Last Name</option>
<Option VALUE="idnumber">ID Number</option>
</Select>
<input type="submit" name="search" value="Search" />
</form>
</body>
</html>
62.
SET
SET
SET
SET
@OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
@OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
@OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
NAMES utf8 */;
(2,'Dizajner');
/*!40000 ALTER TABLE `radno_mjesto` ENABLE KEYS */;
/*!40101
/*!40014
/*!40014
/*!40101
/*!40101
/*!40101
/*!40101
63.
SET
SET
SET
SET
SET
SET
SET
SQL_MODE=@OLD_SQL_MODE */;
FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
COMBO BOX
<?php
//Array contents array 1 :: value
$myArray1 = array('Cat','Mat','Fat','Hat');
//Array contents array 2 :: key => value
$myArray2 = array('c'=>'Cat1','m'=>'Mat1','f'=>'Fat1','h'=>'Hat1');
?>
64.
eMail Subscribe
<?php
include("../../lib/init.php");
$Form = new Base_Form("Subscribe", "frmsubscribe");
$Form->SetPhpCallback("formHandle");
$Form->Add(new Base_Text("Name", "txtname", "", true, new
Base_Validators_NotEmpty("Don't forget to fill in your name.")));
$Form->Add(new Base_Text("Email", "txtemail", "", true, new
Base_Validators_Email("Fill in a valid email address.")));
$Form->Add(new Base_Submit("btnsubmit", "Send"));
function formHandle($data){
// Create file if not exist/Read if file exists
$content = "";
if(!file_exists("subscribers.csv")){
$fileHandle = fopen("subscribers.csv", 'w') or die("can't open
file");
fclose($fileHandle);
}else{
$content = file_get_contents("subscribers.csv");
}
// Add new content to variable
$content .= $data['txtname'] . ";" . $data['txtemail'] . "\n";
// Save content to file
file_put_contents("subscribers.csv", $content);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
error_reporting(E_ALL);
include("../../lib/init.php");
$Form = new Base_Form("Image Uploader", "frmimage");
$Form->SetPhpCallback("formHandle");
$Form->Add(new Base_Text("Name", "txtimage", "", true));
$Form->Add(new Base_File("Image", "fileupload", true, array(new
Base_Validators_File("This is not a valid image. An image must be of type
jpg.", "102400", array("jpg", "gif", "png")), new
Base_Validators_Image("Wrong image size", 300, 300))));
$Form->Add(new Base_Submit("btnupload", "Upload"));
function formHandle($data){
move_uploaded_file($data["fileupload"]["tmp_name"], "upload/" .
$data["fileupload"]["name"]);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Upload Image</title>
<style>
body{
color:#333333;
font-family:Arial,sans-serif;
text-align: center;
background-color: #e1eaf3;
font-size:12px;
}
#wrapper{
margin: 0 auto;
text-align: left;
}
h2{
padding: 30px;
width: 700px;
border:1px solid #97AEC9;
background-color: #FFF;
border-bottom:1px solid #DCE3EB;
margin-bottom:15px;
font-size:18px;
line-height:1.5em;
padding:8px 0 5px;
}
form li{
list-style: none;
list-style-type:none;
margin-bottom: 5px;
display: block;
height: 22px;
padding: 5px;
}
#li_tatext{
height: 60px;
}
#li_lsttype{
height: 120px;
}
form legend{
font-size:18px;
line-height:1.5em;
padding:8px 5px;
}
form fieldset{
border:1px solid #d2e8fa;
margin-bottom:10px;
background-color: #fcfeff;
}
form #label_option_rndradio label{
padding: 0px;
width: 50px;
}
form label{
color:#3E434A;
cursor:pointer;
float:left;
font-size:13px;
width:100px;
padding: 3px 10px 0px 5px;
font-weight:bold;
text-align: right;
}
form input, form textarea, form select{
font-family:Arial,sans-serif;
color:#8B96A4;
float: left;
width:208px;
font-size:13px;
line-height:1;
margin:0;
padding:3px;
}
<?php
error_reporting(E_ALL);
include("../../lib/init.php");
$Form = new Base_Form("Image Uploader", "frmimage");
$Form->SetPhpCallback("formHandle");
$Form->Add(new Base_Text("Name", "txtimage", "", true));
margin-bottom:10px;
background-color: #fcfeff;
}
form #label_option_rndradio label{
padding: 0px;
width: 50px;
}
form label{
color:#3E434A;
cursor:pointer;
float:left;
font-size:13px;
width:100px;
padding: 3px 10px 0px 5px;
font-weight:bold;
text-align: right;
}
form input, form textarea, form select{
font-family:Arial,sans-serif;
color:#8B96A4;
float: left;
width:208px;
font-size:13px;
line-height:1;
margin:0;
padding:3px;
}
form input:focus, form textarea:focus, form select:focus{
color:#333333;
}
form .description{
float: left;
padding-left: 10px;
padding-top: 3px;
color:#666666;
font-style:italic;
}
form .error .description{
display: none;
}
form .error{
background-color:#FFF9D7;
border-color:#E2C822;
}
form .errormessage{
display: inline;
padding-left: 20px;
color:#666666;
font-weight: bold;
}
</style>
</head>
<body>
<div id="wrapper">
<h2>Image Uploader</h2>
<p>This is an image uploader example that shows you how you can validate
the image width, hight, size and type before it's uploaded. In this example
you can only upload jpeg images that are smaller than 300x300 and are
smaller then 100kb</p>
<?php
if(!$Form->Processed()){
echo $Form;
}else{
$data = $Form->GetData();
$currentfile = "upload/" . $data["fileupload"]["name"];
echo '<h2>Success</h2><p><img src="' . $currentfile . '" height="40"
width="40" align="left" hspace="5" />This is the image that you just
uploaded.</p>';
}
?>
</div>
</body>
</html>
67.
<?php
mysql_connect("localhost","root","");
mysql_select_db("faks");
$query = "UPDATE studenti SET ime = '39.99' ";
$result = mysql_query($query);
echo "There were ".mysql_affected_rows()." product(s) affected. ";
?>
68.
Update
<html>
<body>
<?php
$host="localhost";
$uname="root";
$pass="";
$database="faks";
$tablename="studenti";
$connection= mysql_connect($host,$uname,$pass) or die("Database
connection failed!<br>");
$result=mysql_select_db($database) or die("Database could not be
selected");
$query = "UPDATE studenti SET ime=\"new Name 2\" where id=29";
$result = mysql_query($query);
if (!$result) {
die(" Query could not be executed.<br>");
} else {
echo "<table> ";
echo " <tr>";
echo "
<td colspan=\"2\">";
echo "
<center><b>".mysql_affected_rows()." record updated
successfully</b></center>";
echo "
</td>";
echo " </tr>";
echo " <tr>";
echo "
<td>";
echo "
<div align=\"right\"> Name</div>";
echo
echo
echo
echo
echo
echo
"
</td>";
"
<td>".$name. "</td>";
" </tr>";
" <tr>";
"
<td>";
"
<div align=\"right\">E-mail</div>";
echo "
</td>";
echo "
<td>".$email. "</td>";
echo " </tr>";
echo " <tr>";
echo "
<td>";
echo "
<div align=\"right\"> CustomerID</div>";
echo "
</td>";
echo "
<td>".$customerid. "</td>";
echo " </tr>";
echo "</table>";
}
?>
</body>
</html>
69.
<?php
$mysqli = mysqli_connect("localhost", "root", "", "faks");
if(mysqli_connect_errno()) {
die("Could not connect: ".mysqli_connect_error());
}
$query = "SELECT ime, prezime, indeks FROM studenti WHERE ime LIKE
'39.99'";
$stmt = mysqli_prepare($mysqli, $query);
mysqli_execute($stmt);
mysqli_stmt_bind_result($stmt, $ime, $prezime, $indeks);
while(($res = mysqli_stmt_fetch($stmt))) {
echo "Ime: $ime<BR/>\n";
echo "Prezime: $prezime<BR/>\n";
echo "Indeks: $indeks<BR/>\n";
}
if($res === false) {
die("An error occurred fetching: ".mysqli_error($mysqli));
}
mysqli_stmt_close($stmt);
mysqli_close($mysqli);
?>
70.
<?php
@mysql_connect("localhost", "root","") or die("Could not connect to MySQL
server!");
@mysql_select_db("faks") or die("Could not select database!");
$query = "SELECT * FROM studenti";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) :
print $row["prezime"];
endwhile;
mysql_close();
?>
71.
Printanje greke
<?php
$link = mysqli_connect("localhost", "root", "", "faks");
if(!$link) {
$mysql_error = "Connection error: ".mysqli_connect_error();
die($mysql_error);
}
$result = mysqli_query($link, "SELECT * FROM foo");
if(!$result) {
$errno = mysqli_errno($link);
$error = mysqli_error($link);
die("Query Error: $error (code: $errno)");
}
?>
72.
<?php
$mysqli = mysqli_connect("localhost", "root", "","faks", 3306);
$result = mysqli_query($mysqli, "SELECT * FROM studenti");
while($row = mysqli_fetch_array($result)) {
foreach($row as $key => $value) {
echo "$key = $value</BR>\n";
}
}
mysqli_free_result($result);
mysqli_close($mysqli);
?>
73.
Funkcija instaliranje
<?php
function mysqlinstalled (){
if (function_exists ("mysql_connect")){
return true;
} else {
return false;
}
}
function mysqliinstalled (){
if (function_exists ("mysqli_connect")){
return true;
} else {
return false;
}
}
if (mysqlinstalled()){
echo "<p>The mysql extension is installed.</p>";
} else {
echo "<p>The mysql extension is not installed..</p>";
}
if (mysqliinstalled()){
echo "<p>The mysqli extension is installed.</p>";
} else {
echo "<p>The mysqli extension is not installed..</p>";
}
?>
74.
<html>
<head>
<title>Opening a Connection to a Database</title>
</head>
<body>
<div>
<?php
$user = "root";
$pass = "";
$db = "faks";
$link = @mysql_connect( "localhost", $user, $pass );
if ( ! $link ) {
die( "Couldn't connect to MySQL: ".mysql_error() );
}
print "<h2>Successfully connected to server</h2>\n\n";
@mysql_select_db( $db )
or die ( "Couldn't open $db: ".mysql_error() );
print "Successfully selected database \"$db\"<br />\n";
mysql_close( $link );
?>
</div>
</body>
</html>
75.
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("faks");
$result = mysql_query("SELECT * FROM studenti");
if ($result && mysql_num_rows($result)) {
$numrows = mysql_num_rows($result);
$rowcount = 1;
print "There are $numrows people in tabeli studenti:<br
/><br />";
while ($row = mysql_fetch_assoc($result)) {
print "Row $rowcount<br />";
foreach($row as $var => $val) {
print "<B>$var</B>: $val<br />";
}
}
?>
76.
<?php
@mysql_connect("localhost", "root","") or die("Could not connect to MySQL
server!");
@mysql_select_db("faks") or die("Could not select database!");
$query = "SELECT * FROM studenti";
$result = mysql_query($query);
print "<table>\n";
print "<tr>\n<th>id</th><th>ime</th><th>prezime</th>\n</tr>\n";
while (list($id, $ime, $prezime) = mysql_fetch_row($result)) :
print "<tr>\n";
print "<td>$id</td>\n<td>$ime</td>\n<td>$prezime</td>\n";
print "</tr>\n";
endwhile;
print "</table>";
mysql_close();
?>
77.
<?php
mysql_connect("localhost","root","");
mysql_select_db("faks");
?>
78.
<?php
mysql_connect("localhost","root","");
mysql_select_db("faks");
?>
<?php
@mysql_connect("localhost", "root","") or die("Could not connect to MySQL
server!");
@mysql_select_db("faks") or die("Could not select database!");
$query = "SELECT * FROM studenti";
$result = mysql_query($query);
print "<table>\n";
print "<tr>\n<th>id</th><th>ime</th><th>prezime</th>\n</tr>\n";
while (list($id, $ime, $prezime) = mysql_fetch_row($result)) :
print "<tr>\n";
print "<td>$id</td>\n<td>$ime</td>\n<td>$prezime</td>\n";
print "</tr>\n";
endwhile;
print "</table>";
mysql_close();
?>
81.
Ispis redova
<?php
$mysqli = new mysqli("localhost", "root", "","faks", 3306);
$queries = "SELECT * FROM studenti; SELECT * FROM predmeti";
if(mysqli_multi_query($mysqli, $queries)) {
do {
if($result = mysqli_store_result($mysqli)) {
while($row = mysqli_fetch_row($result)) {
foreach($row as $key => $value) {
echo "$key => $value<BR/>\n";
}
}
mysqli_free_result($result);
}
if(mysqli_more_results($mysqli)) {
echo "<BR/>\nNext result set<BR/>\n";
}
} while(mysqli_next_result($mysqli));
}
mysqli_close($mysqli);
?>
82.
<meta charset="utf-8">
<title>Drop-Down Example</title>
<style type="text/css">
/* MAIN NAVIGATION
--------------------------------------*/
#nav{
float: left;
width: 1000px;
height: 25px;
padding: 0px;
margin: 0px;
}
#nav ul {
list-style: none;
padding: 0px;
margin: 0px;
}
#nav ul li {
float: left;
width: auto;
padding: 0px;
margin: 0px;
}
#nav a {
display: block;
width: auto;
height: 25px;
background-color: #fbfbfb;
font-family: arial, helvetica, sans-serif;
font-size: 1.2em;
line-height: 25px;
font-weight: bold;
color: #bbb;
text-decoration: none;
padding: 0 75px 0 0;
margin: 0px;
}
#nav ul li a:hover {
color: #000;
}
/* DROPDOWN MENU - MAIN NAVIGATION
-------------------------------------- */
#nav li ul {
width: 200px;
position: absolute;
left: -999em; /* using left instead of display to hide menus
because display: none isn't read by screen readers */
background-color: #fff;
}
#nav li ul li a {
width: 200px;
height: 20px;
font-weight: normal;
background-color: #fff;
border-bottom: 1px solid #ccc;
padding: 0px;
margin: 0px;
}
#nav li:hover ul, #nav li.sfhover ul { /* javascript IE fix */
left: auto;
width: 200px;
}
</style>
<script type="text/javascript">
sfHover = function() {
var sfEls =
document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp("
sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
</script>
</head>
<body>
<div id="nav">
<ul>
<li><a href="index.php">HOME</a></li>
<li><a href="aboutus.php">ABOUT</a></li>
<li><a href="collections.php">COLLECTIONS</a>
<ul>
<li><a href="mountain.php">MOUNTAIN</a></li>
<li><a href="ocean.php">OCEAN</a></li>
<li><a href="bohemian.php">BOHEMIAN</a></li>
<li><a href="native.php">NATIVE</a></li>
<li><a href="green.php">GREEN</a></li>
<li><a href="moon.php">MOON</a></li>
<li><a href="plants.php">PLANTS</a></li>
</ul>
</li>
<li><a href="offerings.php">OFFERINGS</a>
<ul>
<li><a href="seasons.php">SEASONS</a></li>
<li><a href="installs.php">INSTALLS</a></li>
<li><a href="storefront.php">STOREFRONT</a></li>
<li><a href="lingerie.php">LINGERIE</a></li>
</ul>
</li>
<li><a href="contact.php">CONTACT</a></li>
<li><a href="order.php">ORDER</a></li>
</ul>
</div>
</body>
</html>
83.
Menu google
Navigacija
<head>
<meta charset="utf-8" >
<meta name="viewport" content="width-device-width, initialscale=1.0">
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/bootstrapresponsive.css">
</head>
<div id="oli"><div id="navigacija"><div class="lijevozaobljenje"></div><div id="navigacija-dijelovi" style="text-align:
right"><table width="100%" cellpadding="0" cellspacing="0"><tr
valign="top"><td>
<ol>
<li style="margin-top:2px;"><a href="naslovnica.php"><img width="16"
height="16" src="images/icons/kucica.png" style="background:none"/>
Naslovna</a></li>
<li style="margin-top:2px;"><a href="admin.php?str=korisnici" style="<?php
if($an) echo "color:red"; ?>"><img width="16" height="16"
src="images/zupcanik.png" style="background:none;"> Korisnici </a>
<ol>
<li style="margin-top:2px;"><a href="admin.php?str=literatura"><img
width="16" height="16" src="images/icons/1211806189.png"
style="background:none;"> Literatura</a></li>
Vrijeme
<script language="JavaScript">
var v = new Date()
document.write(v.getHours())
document.write(":")
document.write(v.getMinutes())
document.write(":")
document.write(v.getSeconds())
</script>
86. Petlja if..else
<html>
<body>
<?php
$d=date("D");
if ($d=="Fri")
{
echo "Have a nice weekend!";
}
elseif ($d=="Sun")
{
echo "Have a nice Sunday!";
}
else
{
echo "Have a nice day!";
}
?>
</body>
</html>
REZULTAT:
Have a nice day!
is
is
is
is
is
1
2
3
4
5
88. Niz
<html>
<body>
<?php
$x=array("one","two","three");
foreach ($x as $value)
{
echo $value . "<br />";
}
?>
</body>
</html>
REZULTAT:
one
two
three
89. Print tabele
<?php
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
$data = mysql_query("SELECT * FROM example")
or die(mysql_error());
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>Name:</th> <td>".$info['name'] . "</td> ";
Print "<th>Pet:</th> <td>".$info['age'] . " </td></tr>";
}
Print "</table>";
?>
REZULTAT:
Name:
Name:
Name:
Name:
Name:
Name:
Name:
Name:
MEDA
EMINA
Timmy
Sandy
Bobby
Timmy
Sandy
Bobby
Mellowman
Smith
Wallace
Mellowman
Smith
Wallace
Pet:
Pet:
Pet:
Pet:
Pet:
Pet:
Pet:
Pet:
62
17
23
21
15
23
21
15
90. Datum
<?php
echo date("Y/m/d") . "<br />";
echo date("Y.m.d") . "<br />";
echo date("Y-m-d");
?>
REZULTAT:
2013/08/12
2013.08.12
2013-08-12
91. Print TABELA
<?php
$con=mysqli_connect("localhost","root","","faks");
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error(); }
$result = mysqli_query($con,"SELECT * FROM studenti");
echo "<table border='1'>
<tr>
<th>Ime</th>
<th>Prezime</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ime'] . "</td>";
echo "<td>" . $row['prezime'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
REZULTAT:
Ime Prezime
39.99 emhco
39.99 n
39.99 q
<head>
<meta charset="utf-8">
<title>Drop-Down Example</title>
<style type="text/css">
/* MAIN NAVIGATION
--------------------------------------*/
#nav{
float: left;
width: 1000px;
height: 25px;
padding: 0px;
margin: 0px;
}
#nav ul {
list-style: none;
padding: 0px;
margin: 0px;
}
#nav ul li {
float: left;
width: auto;
padding: 0px;
margin: 0px;
}
#nav a {
display: block;
width: auto;
height: 25px;
background-color: #fbfbfb;
font-family: arial, helvetica, sans-serif;
font-size: 1.2em;
line-height: 25px;
font-weight: bold;
color: #bbb;
text-decoration: none;
padding: 0 75px 0 0;
margin: 0px;
}
#nav ul li a:hover {
color: #000;
}
/* DROPDOWN MENU - MAIN NAVIGATION
-------------------------------------- */
#nav li ul {
width: 200px;
position: absolute;
left: -999em; /* using left instead of display to hide menus
because display: none isn't read by screen readers */
background-color: #fff;
}
#nav li ul li a {
width: 200px;
height: 20px;
font-weight: normal;
background-color: #fff;
border-bottom: 1px solid #ccc;
padding: 0px;
margin: 0px;
}
#nav li:hover ul, #nav li.sfhover ul { /* javascript IE fix */
left: auto;
width: 200px;
}
</style>
<script type="text/javascript">
sfHover = function() {
var sfEls =
document.getElementById("nav").getElementsByTagName("LI");
REZULTAT:
HOME
ABOUT
COLLECTIONS
o MOUNTAIN
o OCEAN
o BOHEMIAN
o NATIVE
o GREEN
o MOON
PLANTS
OFFERINGS
o SEASONS
o INSTALLS
o STOREFRONT
o LINGERIE
CONTACT
ORDER
o
</table>
</form>
</body>
</html>
94.A UNOS INSERT: insert.php
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("faks", $con);
$sql="INSERT INTO studenti (ime, prezime, indeks)
VALUES
('$_POST[ime]','$_POST[prezime]','$_POST[indeks]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
Ime:
Prezime:
Indeks:
Naziv:
95. PASSWORD
<?php
##########################################################################
$password = "admin"; // Modify Password to suit for access, Max 10 Char.
##########################################################################
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Simple Password Protect - PHP PasswordProtect</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!-P { FONT-SIZE: 8pt; COLOR: #000000; FONT-FAMILY: Verdana, Tahoma, Arial}
TD { FONT-SIZE: 8pt; COLOR: #000000; FONT-FAMILY: Verdana, Tahoma, Arial}
-->
</style>
</head>
<body>
<?php
print "<h2 align=\"center\">PHP Simple Password Protect</h2>";
// If password is valid let the user get access
if (isset($_POST["password"]) && ($_POST["password"]=="$password")) {
?>
<!-- START OF HIDDEN HTML - PLACE YOUR CONTENT HERE -->
<p align="center"><br><br><br>
<b>Congratulations</b><br>you have gained access to the Protected and
Secret Area!</p>
<!-- END OF HIDDEN HTML -->
<?php
}
else
{
if (isset($_POST['password']) || $password == "") {
96.INSERT
<?php
// Make a MySQL Connection
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("phpmysql") or die(mysql_error());
// Insert a row of information into the table "example"
mysql_query("INSERT INTO example
(name, age) VALUES('Timmy Mellowman', '23' ) ")
or die(mysql_error());
mysql_query("INSERT INTO example
(name, age) VALUES('Sandy Smith', '21' ) ")
or die(mysql_error());
mysql_query("INSERT INTO example
(name, age) VALUES('Bobby Wallace', '15' ) ")
or die(mysql_error());
echo "Data Inserted!";
?>
REZULTAT:
Data Inserted!
<?php
Rezultat:
Name
Age
Timmy Mellowman 23
Sandy Smith
23
Timmy Mellowman 23
Sandy Smith
21
Bobby Wallace
15
Timmy Mellowman 23
Sandy Smith
21
Bobby Wallace
15
Timmy Mellowman 23
Sandy Smith
21
Bobby Wallace
15
Timmy Mellowman 23
Sandy Smith
21
Bobby Wallace
15
$user
$pass
$database
=
=
=
'root';
'';
'phpmysql123456';
REZULTAT:
Your new table was created successfully!
98. Pravljenje baze
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE gost",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
mysql_close($con);
?>
Database created
99. PRINT TABELA TRI POLJA
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Persons ORDER BY age");
while($row = mysql_fetch_array($result))
{
echo $row['FirstName'];
echo " " . $row['LastName'];
echo " " . $row['Age'];
echo "<br />";
}
mysql_close($con);
?>
REZULTAT:
Glenn Quagmire 33
Peter Griffin 36
Meda Emhco 55
100.
Sesija
<?php
// this starts the session
session_start();
// this sets variables in the session
$_SESSION['color']='red';
$_SESSION['size']='small';
$_SESSION['shape']='round';
print "Done";
?>
REZULTAT:
Done
101 Kreiranje tabele
<?php
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
mysql_query("CREATE TABLE kola ( name VARCHAR(30),
age INT, car VARCHAR(30))");
Print "Your table has been created";
?>
REZULTAT:
Embeded link
Login
<?php
session_start();
if (isset($_POST["submit"])) {
if ($_POST["user"] == "nilanjan" && $_POST["pass"] == "banerjee") {
$_SESSION["usernm"] = $_POST["user"];
}
}
?>
<html>
<head>
<title>User Authentication</title>
</head>
<body>
<?php
if (isset($_SESSION["usernm"])) {
echo("You are logged in!");
} else {
?>
<form method="post">
<input type="text" name="user" /><br />
<input type="password" name="pass" /><br />
<input type="submit" name="submit" value="Login" />
</form>
<?php
}
?>
</body>
</html>
REZULTAT:
103.
<?php
error_reporting(0);
$conn = mysql_connect("localhost:3306", "root", "");
if(!$conn) {
die("Error connecting to MySQL: " . mysql_error());
}
if(!mysql_select_db("adressbook")) {
die("Error connecting to MySQL: " . mysql_error());
}
$self = $_SERVER['PHP_SELF'];
$act = $_GET["act"];
$editing = 1;
$deleting = 1;
if (isset($_GET["rec"])) {
$rec = $_GET["rec"];
} else {
$rec = 1;
};
$key = $_GET["key"];
$count = get_count();
switch ($act) {
case "postins":
if ($editing) {
$modsql = "INSERT INTO `radnik` (`radnik`.`ime`, `radnik`.`posao`,
`radnik`.`status`) VALUES (" ."'"
.for_sql($_POST["radnik_ime_TextBox"]) ."'" ."," ."'"
.for_sql($_POST["radnik_posao_TextBox"]) ."'" ."," ."'"
.for_sql($_POST["radnik_status_DropDownBox"]) ."'" .")";
if ($modsql != "") {
mysql_query($modsql, $conn) or die(mysql_error());
$key = mysql_insert_id();
};
};
header("location: " .$self ."?rec=" .$rec);
exit;
case "postupd":
if ($editing) {
$row = get_current_row();
} else {
$selsql .= " LIMIT 1";
if ($rec > 1) $selsql .= " OFFSET " .intval($rec - 1);
};
$res = mysql_query($selsql, $conn) or die(mysql_error());
return mysql_fetch_array($res);
};
} ?>
<?php function get_count() {
global $conn;
a.button:active {
background-color: #F1F1ED;
color: red;
text-decoration: none;
}
a.disabled:link, a.disabled:visited, a.disabled:active, a.disabled:hover{
background-color: black;
color: #D3D3D3;
text-decoration: none;
cursor: default;
}
/* Other Styles */
body {
margin: 0;
height: 100%;
padding: 10px 10px 10px 10px;
font-family: "MS Sans Serif", sans-serif, Arial;
font-size: 8pt;
color: #1A2127;
}
table.MainTableForm {
border-collapse: collapse;
border-spacing: 0;
border: 2px solid #7F9DB9;
}
table.MainTableForm td {
padding: 6px;
font-size: 8pt;
/*
border: 1px solid #6D943A; */
}
table.MainTableForm td.Column1 {
font-family: "MS Sans Serif", sans-serif, Arial;
background-color: #ECE9D8;
padding-left: 20px;
text-align: right;
font-weight: bold;
}
table.MainTableForm td.Column2 {
font-family: "MS Sans Serif", sans-serif, Arial;
padding-left: 10px;
background-color: #ECE9D8;
}
.FieldName {
}
.InputBox {
font-family: "MS Sans Serif", sans-serif, Arial;
font-size: 9px;
background-color: #ffffff;
border-color: #7F9DB9;
border-width: 1px;
border-style: solid;
background-color: #FAFAFA;
.Picture {
background-color: #354955;
padding: 3px;
}
.Label {
}
table.MainTableGrid {
border-collapse: collapse;
border-spacing: 0;
border: 2px solid #7F9DB9;
}
table.MainTableGrid th {
padding: 3px;
font-size: 8pt;
background-color: #ECE9D8;
border: 1px solid #ACA899;
color: black;
}
table.MainTableGrid th a {
color: black;
}
table.MainTableGrid td {
padding: 3px;
font-size: 8pt;
border: 1px solid #ACA899;
}
table.MainTableGrid td.TableRowEven {
background-color: #F5F7FC;
}
</style>
</head>
<body>
<form name="MainForm" action="<?php if ($act != "add") { echo $self ."?
act=postupd&rec=" .$rec; } else { echo $self ."?act=postins"; } ?>"
method="post">
<table class="MainTableForm">
<tbody>
<tr>
<td class="Column1">
<div class="FieldName">sradnik</div>
</td>
<td class="Column2">
<div class="Label" style="WIDTH: 200px"
name="radnik_sradnik_Div"name="radnik_sradnik_Div"><?php echo
$row["radnik_dbac_fc_sradnik"] ?></div>
</td>
</tr>
<tr>
<td class="Column1">
<div class="FieldName">ime</div>
</td>
<td class="Column2">
<input class="InputBox" style="WIDTH: 200px"
name="radnik_ime_TextBox" value="<?php echo $row["radnik_dbac_fc_ime"] ?
>"name="radnik_ime_TextBox">
</td>
</tr>
<tr>
<td class="Column1">
<div class="FieldName">posao</div>
</td>
<td class="Column2">
<input class="InputBox" style="WIDTH: 200px"
name="radnik_posao_TextBox" value="<?php echo
$row["radnik_dbac_fc_posao"] ?>"name="radnik_posao_TextBox">
</td>
</tr>
<tr>
<td class="Column1">
<div class="FieldName">status</div>
</td>
<td class="Column2">
<select class="InputBox" style="WIDTH: 200px"
name="radnik_status_DropDownBox"name="radnik_status_DropDownBox">
<?php foreach ($radnik_status_DropDownBoxValues as
$radnik_status_DropDownBoxValue) {
if ($radnik_status_DropDownBoxValue ==
$row["radnik_dbac_fc_status"]) { $selstr = " selected"; } else { $selstr =
""; }
?>
<option value="<?php echo $radnik_status_DropDownBoxValue ?>"<?php
echo $selstr ?>><?php echo $radnik_status_DropDownBoxValue ?></option>
<?php } ?>
</select>
</td>
</tr>
</tbody>
</table>
</form>
<br>
<a class="button" id="linkrefresh" href="<?php echo $self ."?rec=" .
$rec ?>">Refresh</a> <a <?php if (!$isfirst) { ?>class="button"<?php } else
{ ?>class="button disabled"<?php } ?> id="linkfirst" <?php if (!$isfirst) {
?>href="<?php echo $self ."?rec=1" ?>"<?php } else { ?>href="#"<?php } ?
>>‹‹ First</a> <a <?php if (!$isfirst) { ?>class="button"<?
php } else { ?>class="button disabled"<?php } ?> id="linkprev" <?php if (!
$isfirst) { ?>href="<?php echo $self ."?rec=" .($rec - 1) ?>"<?php } else {
?>href="#"<?php } ?>>‹ Prev</a> <a <?php if (!$islast) { ?
>class="button"<?php } else { ?>class="button disabled"<?php } ?>
id="linknext" <?php if (!$islast) { ?>href="<?php echo $self ."?rec=" .
($rec + 1) ?>"<?php } else { ?>href="#"<?php } ?>>Next ›</a> <a <?
php if (!$islast) { ?>class="button"<?php } else { ?>class="button
disabled"<?php } ?> id="linklast" <?php if (!$islast) { ?>href="<?php echo
$self ."?rec=" .$count ?>"<?php } else { ?>href="#"<?php } ?>>Last
››</a> <a <?php if ($act != "add") { ?>class="button"<?php }
else { ?>class="button disabled"<?php } ?> id="linkadd" <?php if ($act !=
"add") { ?>href="<?php echo $self ."?act=add" ?>"<?php } else { ?
sradnik 7
medaemhco
ime
posao
status
meda
104.
Datumi
<html>
<body>
<?php
$d=date("D");
if ($d=="Fri")
{
echo "Have a nice weekend!";
}
else
{
echo "Have a nice day!";
}
?>
</body>
</html>
REZULTAT:
SUBMIT
<html><body>
<h4>Tizag Art Supply Order Form</h4>
<form>
<select>
<option>Paint</option>
<option>Brushes</option>
<option>Erasers</option>
</select>
Quantity: <input type="text" />
<input type="submit" />
</form>
</body></html>
REZULTAT:
106.
EMAIL Validation
<html>
<head>
<title>e-mail validator</title>
</head>
<body>
<form name="form1" method="post" action="EMailValidation.php">
<table>
<tr>
<td colspan="2"><b>Enter an e-mail address to test</div></td>
</tr>
<tr>
<td width="25%">E-mail</td>
<td width="75%">
<input type="text" name="email" size="30">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="Submit" value="Submit">
</td>
</tr>
</table>
</form>
</body>
</html>
<!-- EMailValidation.php
<html>
<head>
<title> E-mail validator </title>
</head>
<body>
<?php
if (!isset($email)){
die("Host name value wasn't properly submitted.Retry.");
}
if(empty($email)) {
die("Hostname field was left blank ! Retry.");
}
if ( (strlen($email) < 3) || (strlen($email) > 200)) {
die("Invalid E-mail address, E-mail address too long or too short.");
} elseif(!ereg("@",$email)) {
die("Invalid E-mail address, no @ symbol found");
} else {
echo "<b>".$email."</b> is correct in format.<br>";
}
list($username,$hostname) = split("@",$email);
if ( (empty($username)) or (empty($hostname)) ) {
die("username or host name section is not valid.");
}
if(checkdnsrr($hostname)) {
echo "<b>". $email ."</b> hostname has a valid MX record !<br>";
} else {
die("<b>". $email ."</b> hostname does not exist");
}
?>
<br>
</body>
</html>
-->
REZULTAT:
107.
SUBMIT RESET
<HTML>
<BODY>
<FORM METHOD="POST" ACTION="DealWithArrayFormData.php">
<H1>Contact Information</H1>
<TABLE>
<TR>
<TD>Childrens' Names:</TD>
</TR>
<TR>
<TD><INPUT TYPE="TEXT" NAME="children[]"></TD>
</TR>
<TR>
<TD><INPUT TYPE="TEXT" NAME="children[]"></TD>
</TR>
<TR>
<TD><INPUT TYPE="TEXT" NAME="children[]"></TD>
</TR>
<TR>
<TD><INPUT TYPE="TEXT" NAME="children[]"></TD>
</TR>
<TR>
<TD><INPUT TYPE="TEXT" NAME="children[]"></TD>
</TR>
</TABLE>
<BR>
<BR>
<BR>
<INPUT TYPE="SUBMIT" VALUE="Submit">
<BR>
<BR>
<INPUT TYPE="RESET" VALUE="Clear the Form">
</FORM>
</BODY>
</HTML>
<!-- DealWithArrayFormData.php
<?php
foreach ($children as $index => $child){
echo "<BR>child[$index]=$child";
}
echo "<BR>";
sort($children);
foreach ($children as $index => $child){
echo "<BR>child[$index]=$child";
}
?>
ZAKLJUAK:
108.
<HEAD>
<TITLE>Sat</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function setSat() {
var vr = new Date();
109..