PHP

Warning message

JQuery Cycle must be installed in order to run the slideshow. Please go to Status Report for instructions.

Here we will provide posts related to PHP.

We cannot assign JavaScript variables to PHP directly . To do this AJAX comes into play. You can pass data and variables asynchronously . 

To do this you have to pass HTTP request asynchronously using Jquery Ajax method http://api.jquery.com/jQuery.ajax/ .

To do this first include the Jquery library in your file at the top so that you can use this ajax method . Current version of jquery is 1.10 

you can use this line : <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

Then you have to include the code for sending the variable from javascript to PHP.

$.ajax({
  type: "POST",
  url: "save_data.php",
  data: "title="+strTitle+"&name_email="+name_email+"&result="+result,
   cache: false,
})

In above you have defined POST method , so you can receive the values in save_data.php using $_POST variable easily like $_POST['title'] .

In URL save_data.php is the file where you are sending the javascript variables to php, to use or save the data in the database.

Data string can be made by that or like this :

data: { name: "John", location: "Boston" }

In the end set cache to false, so that it cannot cache the url.

and thats it!

Now you can receive values in your php file and can do the operations with your data.

1. PHP 4 and PHP 5 (up to version 5.1), you can print an object directly. This casts the object to a string
containing the object’s ID. From PHP 5.2 onwards the language no longer supported this magic, and any attempt
to treat an object as a string now causes an error unless a method called __toString() is defined in the object’s
class.

2.The visibility keywords public, private, and protected were introduced in PHP 5. If you are running
PHP 4, these examples will not work for you. In PHP 4, all properties were declared with the var keyword, which is
identical in effect to using public. For the sake of backward compatibility, PHP 5 accepts var in place of public
for properties.

3.PHP 4 does not recognize visibility keywords for methods or properties. Adding public, protected, or
private to a method declaration will cause a fatal error. All methods in PHP 4 are implicitly public.

Pages

Subscribe to RSS - PHP