php - Android & MySQL: Get mysql_insert_id() and retrieve it in Android Activity -
hi have connected mysql in server , android application using json. have table called products primary key , id auto_increment. when insert new product id in android activity don't know how retrieve in php nor android. here code: create product script
if (isset($_post['name']) && isset($_post['price']) && isset($_post['description'])) { $name = $_post['name']; $price = $_post['price']; $description = $_post['description']; // include db connect class require_once __dir__ . '/db_connect.php'; // connecting db $db = new db_connect(); // mysql inserting new row $result = mysql_query("insert products(name, price, description) values('$name', '$price', '$description')");
where should put mysql_insert_id()
?
finally, how mysql_insert_id()
in android activity?
thanks in advance
well, easy:
// mysql inserting new row $result = mysql_query("insert products(name, price, description) values('$name', '$price', '$description')"); $insertedid = mysql_insert_id();
how send id android app? same way send else: json. don't know send app, can easy as
echo json_encode($insertedid);
the usual disclaimer: not use mysql extension anymore, removed php in near future. use mysqli (i = improved) instead, or pdo.
your sql query vulnerable sql injection attacks! never ever put data unescaped directly sql, either use mysql_real_escape_string()
, or use prepared statements.
Comments
Post a Comment