Insert or Update data securely using Json php webservices

21:21:00 2 Comments




Dear Guys I have created this video because I had got a comment on my before video on how to insert data securely using the Json webservices ...This is a frequently asked question so that is the reason why I have created this video..
In this video I have shown you the most important steps to set this type of code it should be really easy..

Below are the code for the most important files

register.php

<?php header('Access-Control-Allow-Origin: *'); ?>
<?php header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); ?>
<?php header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT'); ?>
<?php
include_once('confi.php');
error_reporting(E_ALL);

//Get the variables here
$username = isset($_POST['username']) ? mysql_real_escape_string($_POST['username']) :  "";
$email = isset($_POST['email']) ? mysql_real_escape_string($_POST['email']) :  "";
$password = isset($_POST['password']) ? mysql_real_escape_string($_POST['password']) :  "";
//Get the variables here end/update statement
$insertstatement = 'INSERT INTO `mytesttable`(`id`,`username`,`email`,`password`) VAlUES (NULL,"'.$username.'","'.$email.'","'.$password.'")';

$query123 = mysql_query($insertstatement) or trigger_error(mysql_error()." ".$insertstatement);

//echo "$query123";
//Registration code here (insert statements)

if($query123 == 1){

$result[] = array("status" => 1);
}else{
   $result[] = array("status" => 0); 
    
    
}
/* Output header */
header('Content-type: application/json');
echo json_encode($result);
?>


Post in the javascript that was in login.htm

$.post("http://localhost/loginangulartutorial/webservices/register.php",
    {
        password: confirmpassword,
        email: email,
        username: username
    },
    function(data, status){
        alert("Data: " + data + "\nStatus: " + status);
                
                var status = data[0].status;
                
                if(status == 1){
                    
                    alert('inserted /updated sucessfully');
                }
                if(status == 0){
                    
                    alert('failure statement');
                }
                

    });

I hope that this tutorial was helpful comment below my video in case you have doubts or questions..

Subscribe to my channel http://www.youtube.com/subscription_center?add_user=joeljfernandes

Joel

Joel Fernandes,I am a Very Smart,Innovative Creative and One of the Best Webdevelopers.I am an expert in Webdevelopment.My other interest include Cars and Vehicles.My desire is to be the best and serve you with the best information I have .I will always share all my tips and tricks on this website and provide you with the best themes so that your life may be simpler.Keep visiting www.joelwebsites.com for the best website related ,tips and tricks and news.Meet me on FaceBook

2 comments:

  1. Could you possibly send me an email? I have a question please? Kayndaydaddy@gmail.com

    ReplyDelete

  2. Thank you very much that you shared your experiences, video came out very good and informative. The main thing is that everything is clear and it is really really save my time!
    Richard Brown virtual data room pricing

    ReplyDelete