Latest Post
Tampilkan postingan dengan label get. Tampilkan semua postingan
Tampilkan postingan dengan label get. Tampilkan semua postingan

Passing JavaScript variables to PHP

Written By Unknown on Sabtu, 13 Maret 2010 | 00.21


JavaScript is mainly used as a client side scripting language, while PHP is a server side technology. Unlike Java or ASP.Net, PHP doesn't have tools to make it work client side. That is why you need to combine JavaScript and PHP scripts to develop powerful web-applications.

One of the frequent problems is defining visitor’s screen resolution using JavaScript tools and passing this data to PHP-script. The following script provides solution for this problem:
<script type="text/javascript">

width = screen.width;
height = screen.height;

if (width > 0 && height >0) {
    window.location.href = "http://localhost/main.php?width=" + width + "&height=" + height;
} else
    exit();

</script>

Copy and paste this code snippet in the text editor, save it as index.htm and run it in your browser. After this code has been executed, a user is automatically redirected to the main.php page where screen resolution is displayed in the browser window.
The main.php looks as follows:
<?php
echo "<h1>Screen Resolution:</h1>";
echo "Width  : ".$_GET['width']."<br>";
echo "Height : ".$_GET['height']."<br>";
?>

As you can see, passing JavaScript variables in PHP is similar to sending data using GET method.

PHP $_GET Function

Written By Unknown on Kamis, 31 Desember 2009 | 03.29

The built-in $_GET function is used to collect values in a form with method="get".
The datas sent from a form with the GET  method is visible to everyone ( It will be displayed in the browser's address bar) and has limits on the amount of data to send.

Example:
<form action="welcome.php" method="get">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>

The "welcome.php" file can now use the $_GET function to collect form data (the names of the form fields will automatically be the keys in the $_GET array):

Welcome <?php echo $_GET["fname"]; ?>.<br />
You are <?php echo $_GET["age"]; ?> years old!



Retrieving data from the MYSQL database using PHP

Written By Unknown on Rabu, 09 Desember 2009 | 12.43

In mysql, the SELECT command is used to retrieving data from the database.  We can get the single value or a array of values from the database.
The values are getting from the database by using the following code


$output=mysql_query("SELECT * From table_name");


Here all the results are stored in the variable "output"




If we want to retrieve array of values from the above result,  then we use the following code


$output1 = mysql_fetch_array($result);




Example:


$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM Persons");

while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "
";
  }

mysql_close($con);
 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger