How to change the background, text or a div color on real time with php, mysql, ajax and jQuery ?

Description:- Hello! In this lesson I’ll show you guys the logic with little example to how to change the background, text or a div color on real time with php, mysql, ajax and jQuery.
Maybe you guys have better logics to shorten my code. If you have then please comment below.

So for this lesson make the following files step by step:-
1. create database and name it “color”
2. create row in database(color) and name it colorname
3. Create 2 columns 
    (i) id
    (ii) colorcode
4. Download jQuery file
5. Create changebg.php
6. Create config.php
7. Create insertcolor.php

1. config.php

pdf of config file

2. changebg.php

pdf of changebg file

3. insertcolor.php

pdf of insertcolor file

*NOTE :- I’m providing you pdf files as my wordpress text editor is not working well copy and paste code and make the php files with the same name of files and then goto your browser after making database and then run the changebg.php file.
Live demo is available here

How to replace bad/abusive/swear/curse words through php ??

Description:- Hello guys today’s lesson is only for 18+ public because I really don’t want children to learn abusive words on my blog.
Today I’m going to show you how to replace abusive words through php like if someone typed in FUCK it will display like F**K .

<?php

$string = "Hello asshole I heared that you are asslicker too. Fuck off jerk and never show me your buttface.";
$swearWords = array("asshole","buttface","asslicker","jerk","fuck");
$replacer = array("a**hole","b**tface","a**li***r","j**k","f**k");
$filter = str_ireplace($swearWords,$replacer, $string);

echo $filter;
?>

*Note:- You can also use str_replace() but hence str_replace is case sensitive and str_ireplace() is not a case sensitive so it will accept both types of words lowercase or uppercase words.

How to make Fully functional Contact Form in php using mail() function ?

Description: In this example I’m gonna show you guys how to make fully functional contact form in php using mail() function. And in this example we also cover how to change the placeholder color, how to make captcha code and then will verify if the captcha code is same as you typed in.

I make this contact form for the holding page for my client  the kensington dentist, London.

And most important thing is this contact form is build in Zurb Foundation to make it fully responsive you guys can also use twitter bootstrap….

This example includes 4 different files:-
1. index.php   (In which we make our form)
2. send.php   (through which we’ll send the form it includes mail() function)
3. foundation.css  (its a zurb foundation css file to make the form responsive)
4. app.css  (this will be our custom stylesheet where we’ll give styling to input types and to the placeholders)

————————————————————————————————-
1. index.php

<?php
//  For captcha 
$aa = md5( time() * microtime() );
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Contact form</title>
<meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1, user-scalable=0"/>
<link href='http://fonts.googleapis.com/css?family=Lato:100,300,400,700,100italic,300italic,400italic,700italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="app.css"/>
<link rel="stylesheet" type="text/css" href="foundation.css"/>
</head>
<body>
   
       
                           
                   
                       
                                                   
                       
                                                    
                    </div>                                         
                       
                                                 
                       
                                                    
                    </div>                 </div>                                 
                   
                                           
                </div>                
                    
                        " readonly />                    
                </div>                
                    
                                                 
                </div>                
                   
                                           
                </div>                 
                   
                       

                       

                   
                </div>             </form>         </div>     </div> </div> </body> </html>

2. send.php

<?php
    if($_REQUEST['captcha'] != $_REQUEST['check'])
       {
            header("Location: index.php?error=The characters you entered didn't match the word verification. Please try again.");
       }
    else
       {
            $myemail = "mukul.soni0007@gmail.com";  /*ENTER THE EMAIL ADDRESS WHERE YOU WANT TO RECIEVE THE MAILS. In this case I set it to my personal gmail account. You can also make it dynamic by using $_REQUEST['the name of the field'] */
           
           $name = $_POST['fname'];
           $sname = $_POST['sname'];
           $subject = "Contact Form Submission";    /* Or you can make it dynamic by using $_POST['name of the field'] */
           $email = $_POST['mail'];
           $message = $_POST['message'];
           $tel = $_POST['tel'];
           
           $message="
           Name : $name $sname
           E-mail : $email
           Subject : $subject
           Telephone : $tel
           Message : 
           $message
           ";
           
           /* Send the message using mail() function */
           if(mail ($myemail, $subject, $message))
           {
           
           /* Redirect visitor to the page you guys want */
           header("Location: index.php?success=Thanks! We'll get back to you soon");
           exit(); 
           }
           else{
           /*If any error then throw an error.*/
               echo "Some error Occured !";
               exit();
           } 
       }
?>

3. foundation.css

You guys will find foundation.css here

4. app.css

.cb
{
    border:1px solid #000;
}
.posts-contact ::-webkit-input-placeholder {
   color: #24292d;
    opacity: 0.7;
}

.posts-contact :-moz-placeholder { 
   color:  #24292d;  
}

.posts-contact ::-moz-placeholder { 
   color:  #24292d;  
}

.posts-contact :-ms-input-placeholder {  
   color:  #24292d;  
}

.posts-contact
{
    
    max-width:504px;
    margin:34px auto;
    margin-bottom:0px;
    
}
#captcha
{
    background-color:#fff;
    font-size: 20px;
    font-weight:bold;
    text-shadow: 2px 0px 5px #5ca8fe;
    font-family:'Lato', sans-serif;
    color:rgba(0,0,0,0.5);
    letter-spacing: 10px;
}
.posts-contact input[type="text"],
.posts-contact input[type="tel"],
.posts-contact input[type="email"],
.posts-contact textarea
{
    background-color:#fff;
    box-shadow: 0px 0px 0px;
    text-shadow: none;
    color:rgba(0,0,0,0.75);
    font-family:'Lato', sans-serif;
    border:1px solid #c7c7c7;
    letter-spacing: 1px;
}
textarea
{
    font-family:'Lato', sans-serif;
}
input[type='submit']
{
    background-color:#75b4e2;
    width:171px;
    height:48px;
    border:1px solid #4484b4;
    color:#fff;
    font-family:'Lato', sans-serif;
    font-weight:bold;
    margin-top:28px;
}
input[type='submit']:hover
{
    cursor:pointer;
}
#error
{
    color:#f00;
    font-size:17px;
    padding: 5px;
    font-family: "Lato",sans-serif;
}
#success
{
    color:#2add37;
    font-size:17px;
    padding:5px;
    font-family: "Lato",sans-serif;
}

Note:-
1. Please whenever you use this contact form please change the email address inside send.php file which is wrapped in $myemail variable otherwise I’ll get all your mails.
2. It is possible that you can not find the mail in your inbox. So don’t forget to check spam folder
3. Keep all 4 files in the same folder.
4. You need a server to check this. Without server its just a static contact form. It will work only online.
If you want to see the live example of this form you can go to my testing server i.e jaiupur4ever .

To watch the video of php mail function

Web addict is company now :)

Hi folks,
Recently we registered our company Web Addict. Where you can see our various work for companies, Beauty products, Startup and personal portfolio. You can just hire us in an attractive price based on your requirement..

Feel free to have to look on webaddict.in

How to upload multiple images in one time through PHP ?

Description:- Through this example you can easily come to know how to upload multiple images in one time by selecting the images through ctrl button.

<!-- Uploading multifiles by webtechball -->
<!-- www.webtechball.wordpress.com -->
<!DOCTYPE html>
<head>
<title>Multifile uploading by Webtechball</title>
<style>
img{margin:10px 0 0 10px; border:1px inset rgba(51,51,51,1);}
</style>
</head>
<body>
<center>
<form action="<?php $_PHP_SELF; ?>" method="post" enctype="multipart/form-data">
    <input type="file" name="multiImgs[]" multiple/> 
    <input type="submit" name="upload" value="Upload"/>
</form>

<?php
if(isset($_REQUEST['upload']))
{
    //Inserting the name of the files into the loop, so that it will upload each and every file
    for($a=0; $a < count($_FILES['multiImgs']['name']); $a++)
    {
        move_uploaded_file($_FILES['multiImgs']['tmp_name'][$a],"upload/".$_FILES['multiImgs']['name'][$a]);
        echo "<img src='upload/".$_FILES['multiImgs']['name'][$a]."' width=100px height=100px/>"
        //Printing each and every files with loop
    }
}

?>
</center>
</body>
</html>

*Note :- Copy the code and paste in your text editor and save it in your htdocs and
don’t forget to create a new folder and rename it as “upload”. This will be your folder where your uploaded files will going to be save.
   

How to send email through php ?

Description:- In this example I’m gonna show you guys how to make your own fully functional custom contact us form for your own site. So this example is done in two different parts.
Step1:- The HTML part, which is the form and we named that form.php
Step2:- The php part and we named that email.php

*NOTE :-  To run this example you have to purchase your own hosting server. IT WON’T WORK OFFLINE…..

Step1:-   form.php

<!DOCTYPE html>
<head>
<title>Sending email</title>
<link rel="stylesheet" href="bootstrap.min.css" type="text/css"/>
<script src="bootstrap.min.js" type="text/javascript"></script>
<script src="jquery-1.11.1.min.js" type="text/javascript"></script>
</head>
<body>
<div class="container" style="margin:5% auto">
<div class="row">
<div class="col-lg-4"></div>
<div class="col-lg-4" style="box-shadow:1px 1px 1px 2px #CCCCCC; border-radius:1%; padding:3%;">
<form role="form" action="email.php" method="post">
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" class="form-control"/>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="text" name="email"  class="form-control"/>
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea class="form-control" name="message" rows="5"></textarea>
</div>
<input type="submit" name="sub" value="Send" class="btn btn-primary pull-right"/>
</form>
</div>
<div class="col-lg-4"></div>
</div>
<?php echo $_REQUEST['do']; ?>
</div>
</body>
</html>

 Step2:-  email.php

 <?php
if(isset($_REQUEST['sub']))
{
    $admin = "This msg came from Mr/Ms: ".$_REQUEST['name']. "<br/>"
            . "His/Her email address is: ".$_REQUEST['email']. "<br/>"
            . "His/Her message is: ".$_REQUEST['message'];
            
    mail('webtechball.wordpress.com', 'Sample subject for this example', $admin); 
    //In this example I entered "webtechball.wordpress.com" just for the example, you write your own valid mail address. 
    //In for the sample I entered "Sample subject for this example" for this example you write your own subject line.
    
    header("location:form.php?do=Thanks for your valuable message. We'll contact you as soon as possible");
}
else
{
    header("location:form.php?do=Please try again");
    
}
?>

*NOTE :-  To run this example you have to purchase your own hosting server.
IT WON’T WORK OFFLINE…..

How to create Viewer or visitor counter for our website through php ?

Description:- Below is the code through which we can easily make viewer counter for our website. It will also work offline on your local machine, just refresh the page and it will increase the count. Through this you can count the views on your website. I call this viewer counter.

<?php
$file = "countfile.txt";
$a = file_get_contents($file);
$r = $a+1;
$create = fopen($file,"w");
fwrite($create,$r);

?>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View counts</title>
<style>
.view{background:rgba(0,0,0,1); color:rgba(0,204,255,1); border:2px inset rgba(153,153,153,1); width:100px;  text-align:center; padding:10px; font-size:2em;}
</style>
</head>
<body>
<center>
<h2>You are viewer number:</h2> <div class="view"><?php echo $r; ?></div>
</center>
</body>
</html>

*Note:- When you run this code in your web browser, first time it will show a warning i.e;
” Warning: file_get_contents(countfile.txt) [function.file-get-contents]: failed to open stream ” because the file countfile.txt is not yet created. But after refreshing it second time the above php code will generate the countfile.txt automatically and it won’t show the warning again. And I styled the div according to me you can style it according to your need. Have fun guys.
Happyyyy Coding !
Happyyyy Coding !
😉