【发布时间】:2013-06-16 19:52:00
【问题描述】:
我有一个像下面这样的小 php 页面,我想从这个插入返回“auto-incremented_id”。
唯一的要求是我可以从 android 应用程序中读取数字。我确定我可以查一下,但是否有一个代码 SQL 我可以检查成功后返回它的代码?
这是 php:
<?php
//Make connection
$con = mysqli_connect('xxxxx', 'xxxxxxx', 'xxxxx');
//check connection
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
//change db to andriodnfp db
mysqli_select_db($con, 'andriodnfp');
$table = 'USER';
$fbid = htmlspecialchars($_GET["fbid"]);
$social = htmlspecialchars($_GET["social"]);
$name = htmlspecialchars($_GET["name"]);
$name = !empty($name) ? "'$name'" : "NULL";
$fname = htmlspecialchars($_GET["fname"]);
$fname = !empty($fname) ? "'$fname'" : "NULL";
$username = htmlspecialchars($_GET["username"]);
$username = !empty($username) ? "'$username'" : "NULL";
$email = htmlspecialchars($_GET["email"]);
$email = !empty($email) ? "'$email'" : "NULL";
$picture = htmlspecialchars($_GET["picture"]);
$picture = !empty($picture) ? "'$picture'" : "NULL";
$other = htmlspecialchars($_GET["other"]);
$other = !empty($other) ? "'$other'" : "NULL";
if (!$fbid == '') {
if (!mysqli_query($con, 'INSERT INTO ' . $table . ' ( facebookID, social_outlet, Name, first_name, username, email, picture, significant_other) VALUES ("' . $fbid . '","' . $social . '","' . $name . '","' . $fname . '","' . $username . '","' . $email . '","' . $picture . '","' . $other . '")')) {
printf("Errormessage: %s\n", mysqli_error($con));
};
}
mysqli_close($con);
//$posts = array($json);
$posts = array(
1
);
header('Content-type: application/json');
echo json_encode(array(
'posts' => $posts
));
?>
【问题讨论】:
-
反正它不属于
android。 -
这与如何在Anroid应用程序中读取json有关..
-
如果有问题的代码在 PHP 和 MySQL 之间,那么即使使用其他语言,它们也不相关。
-
感谢它已从 android 中删除,不便之处。
标签: php json mysqli auto-increment