session_start(); } include "Include/checkTutor.php"; ?> <html> <head> <link rel="stylesheet" type="text/css" href="Include/Css.css"> <?php include "include/head.php"; ?> </head> <body> <div id="content"> <?php if (isset($_POST['checkbox'])) { addUserToDatabase(); } else { showForm(); } ?> </div> </body> <footer> <?php include "Include/footer.php"; ?> </footer> </html>
global $requestAck; setRequestAck(REGISTER_FAILED, "Problem: file is not image: {$uploadFileType}", ""); print json_encode($requestAck); exit; } $sexInt = $sex == "男" ? 1 : 0; $userID = generateUserID(); $storedFileName = getFileURLForStore($userID); // 数据校验 if (!isNicknameAvailable($nickName)) { setRequestAck(REGISTER_FAILED, "哎呀,名字已经被使用了", $userID); print json_encode($requestAck); exit; } saveUploadFile($storedFileName); addUserToDatabase($userID, $nickName, $storedFileName, $phoneNumber, $sexInt); //写入数据库 function addUserToDatabase($id, $nickName, $avatar, $phone, $sex) { global $userID, $requestAck; $conn = db_connect(); $conn->set_charset("utf8"); // 指定数据库字符编码 $result = $conn->query(" insert into user(userid, nickname, avatar, sex, phone) values(\"{$id}\", \"{$nickName}\", \"{$avatar}\", {$sex}, \"{$phone}\");"); if (!$result) { //$result->free(); // 插入语句不用free? $conn->close(); setRequestAck(REGISTER_FAILED, "Insert user info to database failed.", $userID); print json_encode($requestAck); exit; }