Hi all,
Today I would like to explain about inserting data to database using PHP, like we do it in jQuery AJAX. For this first we have to create a PHP file. We can use the following code to insert a data to database. We already have a database named ‘testingpurpose’ and we get data from ‘demologin table.Here is a simple example of insert data from front end to mysql database using angularjs.
insertdb.php
uname); $upswd = mysqli_real_escape_string($con,$data->pswd); $uemail = mysqli_real_escape_string($con,$data->email); $qry_em = 'select count(*) as cnt from demologin where username ="' . $usrname . '"'; $qry_res = mysqli_query($con,$qry_em); $res = mysqli_fetch_assoc($qry_res); if ($res['cnt'] == 0) { $qry = 'INSERT INTO demologin (username,password) values ("' . $usrname . '","' . $upswd . '")'; $qry_res = mysqli_query($con,$qry); if ($qry_res) { $arr = array('msg' => "User Created Successfully!!!", 'error' => ''); $jsn = json_encode($arr); print_r($jsn); } else { $arr = array('msg' => "", 'error' => 'Error In inserting record'); $jsn = json_encode($arr); print_r($jsn); } else { $arr = array('msg' => "", 'error' => 'User Already exists with same email'); $jsn = json_encode($arr); print_r($jsn); } ?>
Now we add our AngularJS script to insert data from front end to mysql database .
AngularJs Insert Data to database
Thanks for reading.
What does this do? mysqli_real_escape_string($con,$data->uname);
I don’t see uname anywhere else in the code so wondering how / why that’s used
‘uname’ is a table field in database.
Its working fine for duplicate entry in database. but how can views inserted data???
Refer http://prittytimes.com/angularjs-reading-json-data/
Thanks so much for this tips…..i really appreciate 🙂 🙂 🙂