Display PHP Errors

PHP Error Display Setting: 

If we need to be experienced developer, it’s very important to work with errors and working.
This always helps us to write errors less code. 

Then it’s very important to write proper error handing code, but I always prefer error handing code on live environment and not on development or test environment.

Sometime error are displaying in PHP this could be due to you have implementing error suppress code or another silly reason that we are looking in other function.

Use below code that will help to show the error on your PHP code or file.

<?php
   
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
  
?>

The above code will display error on your PHP file. In case error are still not displaying , you have to check the php.ini configuration . You have to check PHP file configuration.
Make below change to reflate error on page.

File Name: php.ini
Change needed:  display_errors = on


In case you are still facing issue with this code , please make a comment and add your any suggestions.

1 comment :

Post a Comment

Leave A Comment...

PHP Switch Cases

PHP Switch Cases
PHP Cases or switch case is better alternative  for If .. Else statements
Switch case is predefined systematic conditions that can execute run time.
Syntax: PHP Switch cases.


<?php



Switch(Variable Name)
{
Case 'Check 1':
echo 'print output';
break;

Case 'Check 1'
echo 'print output';
break;

default
echo 'print output';

}

?>

Description: Variable is nothing but a conditional parameter to pass a value to switch cases, these cases will check exact match with variable value and gives the result.

Example:


<?php

$day="Friday";

Switch($day)
{
Case 'Monday':
Echo ‘Todays discount is 30%’;

Case 'Friday'
Echo ‘Todays discount is 40%’;
}
Default
echo "No discount";




?>
Output: Todays discount is 40%

If when there is no marching condition found then it will execute the default statement and give the default result.

Example 2: for default execution
<?php

$day="Friday1";

Switch($day)
{
Case 'Monday':
Echo ‘Todays discount is 30%’;

Case 'Friday'
Echo ‘Todays discount is 40%’;
}
Default
echo "No discount";




?>
Output: No discount


No comments :

Post a Comment

Leave A Comment...

PHP Intro

PHP has lots many things to do, you can explore the many thing in PHP for your web development. PHP
To learn PHP, we have to understand some basics behind the PHP.  
That it, how to write PHP? How to make comment?  I.e.  To hide from complier and readable in program pan, Variable declaration, syntax, operators etc.,
Let’s see how to make a comment.



Comment in PHP

Comment using * asterisk mark 
Comment using double foreword slash // & hash # sign, comment using this sign called as single line comment

<!DOCTYPE html>

<html>
<body>
<?php
/*
Use of forward slash with asterisk mark is Multi-line comment. You can use if your to add for your program description or whenever is necessary, all the comments or code written inside the comment will not be complied by php compiler. 
*/

// Here, I am using double forward slash; this is a single line comment.
# Here, I am using only hash sign, this is also a single line comment.
?>
</body>
</html>



Variable declaration in PHP 

PHP has its own unique style to declare the variables.  PHP does not have any predefined notation to declare the type of variable for example , number , text etc.  its advantage of disadvantage that clearly depends on your thinking. 

 The moment  when you assign some value to that variable , then that variable becomes that type  variable.  PHP is uses “Dollar” Sign ($) to declare any variable. User this $ sign as prefix to every alphanumeric character. 

Note 1     : Variable don't accepts hyphens , space and numeric start. 
Notes 2  : PHP statement always ends with semicolon.
 Notes 3 : Without quotes text Variable value should be only number and it should not be text.

Below are NOT valid declarations.

$2carname="BMW" ;
$2car-name="BMW";
$2car name="BMW";
$2carname=BMW ;

Below are the valid declarations.

$carname="BMW" ;
$car_name="BMW" ;
$car_2name="BMW" ;


Sample code:

<!DOCTYPE html>
<html>
<body>
<?php
$a=10// Variable $a is declared and value 10 is assigned to it
$b=20// Numeric variable $b  as declared
$c=null// Variable declared $c  as null, null is assigned to variable $c
?>


</body>
</html>


Is variable case sensitive in PHP?  Yes

Is variable case sensitive in PHP? Yes, it’s true; variables are case sensitive in PHP.
You can create same name variables by changing its case.
Sample Code:A


<! DOCTYPE html>
<html>
<body>
    <?php
    $x=10;
    $X=20;
    $y=$x+$X;
    echo $y;
    ?>
</body>
</html>

Output:

30


Sample Code:B - Check the differance between two varibales , in below example x is assigned to 10 on first line and on second line x is assigned to 20, that meanse second variable will overwrite to first one and the result container $y will display total of both $x is 40


<! DOCTYPE html>
<html>
<body>
    <?php
    $x=10;
    $x=20;
    $y=$x+$x;
    echo $y;
  ?>
</body>
</html> 
Output: 
40

No comments :

Post a Comment

Leave A Comment...

PHP "Cannot modify header information - headers already sent" Solved!

Warning: Cannot modify header information - headers already sent by

To fix this error I have faced many challenges. You might have seen many resolutions on this, but sometime this could be very difficult to fix in existing templates. But finally I got the correct resolutions, I applied three methods out of this I was able to apply one fix that help to correct my existing template.  
But, I will explain all three methods, so that any of the method you can try to your template to fix your issue.

Suppress your error: If you are sure, the one error you are facing on your template, that is because of know function or because of known PHP page.
Then you can use below error suppress method.
Just put this function above to that function or on the top of your .php page.
Example:

Syntax:
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
<?php
error_reporting(0);
// your function/page code will be here.
?>
 Note: I am recommending this only when you are aware which function throwing an error or which page is throwing an error.

Turn off PHP Output Buffeting: As this method was applicable for PHP template. So used this methods and its worked like champ. I recommend this method for your problem.

To use this method, just keep one thing in mind, you have to use this function on very first line of your PHP file. Don’t forget to use on first line. It will skip header buffeting from your error script. You will not face “Header Already sent” error anymore on your script.
Example:
<?php
ob_start()
// your function should start from hear.
Function myFunction()
{
//your code will go hear
}
?>
3. Apply if condition on Header Sent warning: It’s a simple method to solve your warning message.  check if header already sent then do not set header again. Skip your that error code
Example:


<?php
   
if (headers_sent()) {
    die("Redirect Error");
}
else{
    exit(header("Location: /myPage.php"));
}
?>


3 comments :

Post a Comment

Leave A Comment...

Dynamically Load More Table Rows Example by JQuery -Simple & Useful Developer tool


Load more table rows by JQuery : Below is the jQuery based load more table example > Many time we need this functionality to be developed in our website application and its a time taking job, if its not already developed in your application, So I have created this example to save your time , you have to just copy and paste this code to your application.
The two things you have consider before using this code to your application . Use any jQuery framework,it could be 1.8.1 or 1.1.1, t This code will work smoothly on any jQuery framework without any issue. Now the second part is you need to change table id instead of existing one. whichever applicable to your application or you have use the same one.
Now the configuration part , you just have to change one line i.e. row2disaply, default I have added 4 rows to display ,you can change it as per your requirement.
If you think this code will importer much better , please leave your comment or contact me. Thanks

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script> $(function() { var totalrowshidden; var rows2display=4; var rem=0; var rowCount=0; var forCntr; var forCntr1; var MaxCntr=0; $('#hide').click(function() { var rowCount = $('#jsWebKitTable tr').length; rowCount=rowCount/2; rowCount=Math.round(rowCount) for (var i = 0; i < rowCount; i++) { $('tr:nth-child('+ i +')').hide(300); } }); $('#show').click(function() { rowCount = $('#jsWebKitTable tr').length; MaxCntr=forStarter+rows2display; if (forStarter<=$('#jsWebKitTable tr').length) { for (var i = forStarter; i < MaxCntr; i++) { $('tr:nth-child('+ i +')').show(200); } forStarter=forStarter+rows2display } else { $('#show').hide(); } }); $(document).ready(function() { var rowCount = $('#jsWebKitTable tr').length; for (var i = $('#jsWebKitTable tr').length; i > rows2display; i--) { rem=rem+1 $('tr:nth-child('+ i +')').hide(200); } forCntr=$('#jsWebKitTable tr').length-rem; forStarter=forCntr+1 }); }); </script> <table id="jsWebKitTable" style="width:100%"> <tr> <td>JavaScriptWebKit_td1</td> <td>JavaScriptWebKit_td2</td> <td>1</td> </tr> <tr> <td>JavaScriptWebKit_td1</td> <td>JavaScriptWebKit_td2</td> <td>2</td> </tr> <tr> <td>JavaScriptWebKit_td1</td> <td>JavaScriptWebKit_td2</td> <td>3</td> </tr> <tr> <td>JavaScriptWebKit_td1</td> <td>JavaScriptWebKit_td2</td> <td>4</td> </tr> <tr> <td>JavaScriptWebKit_td1</td> <td>JavaScriptWebKit_td2</td> <td>5</td> </tr> <tr> <td>JavaScriptWebKit_td1</td> <td>JavaScriptWebKit_td2</td> <td>6</td> </tr> <tr> <td>JavaScriptWebKit_td1</td> <td>JavaScriptWebKit_td2</td> <td>7</td> </tr> <tr> <td>JavaScriptWebKit_td1</td> <td>JavaScriptWebKit_td2</td> <td>8</td> </tr> <tr> <td>JavaScriptWebKit_td1</td> <td>JavaScriptWebKit_td2</td> <td>9</td> </tr> <tr> <td>JavaScriptWebKit_td1</td> <td>JavaScriptWebKit_td2</td> <td>10</td> </tr> <tr> <td>JavaScriptWebKit_td1</td> <td>JavaScriptWebKit_td2</td> <td>11</td> </tr> <tr> <td>JavaScriptWebKit_td1</td> <td>JavaScriptWebKit_td2</td> <td>12</td> </tr> <tr> <td>JavaScriptWebKit_td1</td> <td>JavaScriptWebKit_td2</td> <td>13</td> </tr> <tr> <td>JavaScriptWebKit_td1</td> <td>JavaScriptWebKit_td2</td> <td>14</td> </tr> <tr> <td>JavaScriptWebKit_td1</td> <td>JavaScriptWebKit_td2</td> <td>15</td> </tr> <tr> <td>JavaScriptWebKit_td1</td> <td>JavaScriptWebKit_td2</td> <td>16</td> </tr> </table> <input id="show" type="button" value="Load More Table Rows..... "/> 

Try this- Load More Table Rows Example by JQuery



JavaScriptWebKit_td1 JavaScriptWebKit_td2 1
JavaScriptWebKit_td1 JavaScriptWebKit_td2 2
JavaScriptWebKit_td1 JavaScriptWebKit_td2 3
JavaScriptWebKit_td1 JavaScriptWebKit_td2 4
JavaScriptWebKit_td1 JavaScriptWebKit_td2 5
JavaScriptWebKit_td1 JavaScriptWebKit_td2 6
JavaScriptWebKit_td1 JavaScriptWebKit_td2 7
JavaScriptWebKit_td1 JavaScriptWebKit_td2 8
JavaScriptWebKit_td1 JavaScriptWebKit_td2 9
JavaScriptWebKit_td1 JavaScriptWebKit_td2 10
JavaScriptWebKit_td1 JavaScriptWebKit_td2 11
JavaScriptWebKit_td1 JavaScriptWebKit_td2 12
JavaScriptWebKit_td1 JavaScriptWebKit_td2 13
JavaScriptWebKit_td1 JavaScriptWebKit_td2 14
JavaScriptWebKit_td1 JavaScriptWebKit_td2 15
JavaScriptWebKit_td1 JavaScriptWebKit_td2 16



No comments :

Post a Comment

Leave A Comment...