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.
Wonderful items from you, man. I’ve have in mind your stuff previous to and you’re simply extremely great.
I actually like what you have got right here, really like what you are stating and the best
way by which you are saying it. You’re making it entertaining and you
still care for to keep it wise. I can not wait to learn much more from you.
This is really a wonderful site.
Hi! Do you know if they make any plugins to assist with SEO?
I’m trying to get my site to rank for some targeted keywords but I’m not seeing very good gains.
If you know of any please share. Kudos! You can read similar art here: Eco wool
‘uname’ is a table field in database.
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
Refer http://prittytimes.com/angularjs-reading-json-data/
Its working fine for duplicate entry in database. but how can views inserted data???
Thanks so much for this tips…..i really appreciate 🙂 🙂 🙂