Posts

Showing posts from 2014

Draw pyramid shape of stars in PHP using loop structure Write down the code in PHP using loop structure to draw the 3 pyramid shapes of stars as given bellow:

Image
ravimanephpmysql // problem 01 solution for($i=5;$i>=1;$i--) { echo  str_repeat('*',$i); echo "<br />"; } echo "<hr />"; // problem 02 solution for($i=1;$i<=5;$i++) { echo  str_repeat('*',$i); echo "<br />"; } echo "<hr />"; // problem 03 solution $j=1; for($i=5;$i>=1;$i--) { //echo  str_repeat("&nbsp;",$i-1); echo  str_repeat('*',$j++); echo "<br />"; }

Get PHP to display warnings and errors only not Notice

Just put the Below code in Php.ini error_reporting = E_ALL & ~E_NOTICE;

PHP - Getting notice Undefined index

      Question: I am getting the following message: Notice: Undefined index: action in /home/fhlinux170/c/cybernet-designs.co.uk/user/htdocs/formtest.php on line 17 . Line 17 contains this line of code if($_POST['action'] == "send") Anwser  This error appears because of your PHP error reporting settings. Usually, it appears when your variable is not properly set. There are two ways to handle this issue: 1. Check if $_POST['action'] is set before using it. For example: if (! isset ( $_POST [ 'action' ])) { //If not isset -> set with dumy value $_POST [ 'action' ] = "undefine" ; } 2. Suppress Notice warnings Notice warnings could be suppressed by changing the error_reporting variable in your PHP.ini. error_reporting  could be set to show all errors except those for notices and coding standards warnings:  error_reporting = E_ALL & ~E_NOTICE The same is accomplished by adding the following line in your

How do I turn off PHP Notices, Error and Warning?

Just write the below code <? php // Turn off all error reporting error_reporting ( 0 ); ?>

How manage session between three page in php.

PHP do you want user visit first page then and then go second. user can't go directly on secong page using web URL. e.g. login validation required for future process. below i written three php file and creating session between this file . f irst page index.php <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html>     <head>         <meta charset="UTF-8">         <title></title>     </head>     <body>         <?php         session_start();         if ($_SESSION['name'] != "$name") {             $currentvalue = $_SESSION['name'];             header("location:$currentvalue.php");         } else {             ?>             <form action="" method="post" name="ind">                 <i

Make an image responsive - simplest way

You can try doing <p> <a href = "MY WEBSITE LINK" target = "_blank" > <img src = "IMAGE LINK" style = ' width : 100% ; ' border = "0" alt = "Null" > </a> </p> This should scale your image if in a fluid layout. For responsive (meaning your layout reacts to the size of the window) you can add a class to the image and use @media queries in css to change the width of the image.

how to create template file in php. why it is usefull

ravimane and php,mysql     that code that is same in two page no need to write twice , just make one file having that code and call or include anywhere you want.     everyone have been trying with .tpl.php extension. but doesn't matter what you want take, but with .php extension. that cool na  .so check out below and seek whatever you want .     below i made three file         top.php <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link rel="stylesheet" href="css/style.css" type="text/css"> <meta name="Author" content="YOUR NAME HERE"> middle.php </head> <body> <div id="banner"> <img src="xyzlogo.gif" alt="XYZ, Inc. logo"> </div> <div id="menu"> <a href="index.php">Home</a> | <a href="sitemap.php">Sitemap</a> | <a hr

stop inserting data in the database when refreshing the page.

The best way to prevent that is to add header('Location: filename') after your query. Thus in your case, if ( isset ( $_POST [ 'submit' ])) { $user = $_POST [ 'username' ]; $email = $_POST [ 'useremail' ]; $pass = $_POST [ 'password' ]; mysql_query ( "INSERT INTO table (username, useremail, email) VALUES ('$username','$useremail','$email'); //must be inside the condition to prevent too many redirects header('Location: user_details_page.php'); }

how to work ajax and php in single code

this link show what do you wanted    its' simpler and great demo http://simpletutorials.com/?path=tutorials/javascript/simple_ajax

PHP: give alert popup then redirect the page

Do something like header ( "Location: index.php?Message=" . urlencode ( $Message )); Then on index.php... if ( isset ( $_GET [ 'Message' ])) { print $_GET [ 'Message' ]; } In other words, index.php will always check if it's being passed a message in the url. If there is one, display it. Then, just pass the message in the redirect if you really want to use a modal popup, generate the js... if ( isset ( $_GET [ 'Message' ])) { print '<script type="text/javascript">alert("' . $_GET [ 'Message' ] . '");</script>' ; }

PHP: give alert popup then redirect the page

code goes this   if ( $_FILES [ 'file' ][ 'size' ] > 200000 ) //any file size, 200 kb in this case { echo "<script type='javascript'>alert('File size larger than 200 KB')</script>" ; } header ( "Location: index.php" );         The browser will be redirected to index.php page anyway, no matter the file is successfully uploaded or not. Its just that the popup will appear if the file is of larger size.

Javascript Confirm Delete in One PHP File (on href)

You can set the onclick attribute of the link. If the function returns false , the link will not proceed. <a href = "deletephone.php?id=' . $row['id'] . '" onclick = " return confirm ( 'Are you sure?' ); " > Delete Phone </a> Here, the confirm() function will return true if the user pressed OK, and false if the user pressed Cancel.

echo javascript with single quotes

You are echoing outside the body tag of your HTML. Put your echos there, and you should be fine. Also, remove the onclick="alert()" from your submit. This is the cause for your first undefined message. <? php $posted = false ; if ( $_POST ) { $posted = true ; // Database stuff here... // $result = mysql_query( ... ) $result = $_POST [ 'name' ] == "danny" ; // Dummy result } ?> <html> <head></head> <body> <? php if ( $posted ) { if ( $result ) echo "<script type='text/javascript'>alert('submitted successfully!')</script>" ; else echo "<script type='text/javascript'>alert('failed!')</script>" ; } ?> <form action = "" method = "post" > Name: <input type = "text" id = "name" name = &qu

why we use this function mysql_real_escape_string()

when we are entering data in to mysql database and that contain the single quote. that time data is not entering into database and showing error then we we use this function . there are other function to remove the the to remove the quote but this one is easier one thank you

MySQL error: “Column count doesn't match value count at row 1” - beginner help

I understand that you're not providing a value since it's likely a PRIMARY KEY that autoincrements. To tell MySQL that you are intentionally not passing a value for that column, you should add NULL as the first value.

need to remove an apostrophe ‘ from a string

$newaddress = str_replace("'", "", "$address"); That should work, for other answers visit [ php.net ...]

MySQL error when inserting data containing apostrophes

this should work....... $result=mysql_query("INSERT INTO $table wf_FirstName1,wf_LastName3) VALUES ('".mysql_real_escape_string($wf_FirstName1)."', '".mysql_real_escape_string($wf_LastName3)."')"; :)

MySQL error when inserting data containing apostrophes (single quotes)

Apostrophe Delimiter In the MySQL version of SQL, you signal the beginning and the end of a string with either single quotes or double quotes. Both of the following examples are valid: INSERT INTO COMPANY_TABLE (company_name) VALUES ‘The Fish Shack’; INSERT INTO COMPANY_TABLE (company_name) VALUES “The Fish Shack”; The following example, however, creates an error: INSERT INTO COMPANY_TABLE (tag_line) VALUES ‘Eat at Joe’s -- It’s Good Food!’; SQL wants to interpret the string as "‘Eat at Joe’," with everything following the second apostrophe as erroneous. The following text does not fix the problem: INSERT INTO COMPANY_TABLE (tag_line) VALUES “Eat at Joe’s -- It’s Good Food!”; This would work if the text had only one apostrophe between the double quotes, but this text has two. Also, because some Web-page programming languages use double quotes themselves, you may wish to avoid using them in your SQL.

What is PHP.

PHP is server side scripting language. that's the way all are define. why server side scripting.        the code we are written in php is executing on server side and what ever the output come out is shown as html form.