dream198731 2013-06-20 12:14
浏览 88
已采纳

为什么MySQLI INSERT不起作用? [关闭]

My MySQLI INSERT query wont work.

Nothing is getting passed to the database in the query.

Everything else is working great, so I don't know why the query wont work.

This is all part of an AJAX call, and I know the data is being received correctly, and also there is a successful return.

PHP

//Get all POST data from user trying to register
$username = $_POST['username'];
$password =  $_POST['password'];
$name = $_POST['name'];
$email = $_POST['email'];
$lat = $_POST['lat'];
$lon = $_POST['lon'];

//Choose wether the user will be "it" or "not it"
$choose_it = array('it', 'not it');
$key = array_rand($choose_it);
$it = $choose_it[$key];

$message = "";

$allEmails = "";
$allUnames = "";

//Get emails from registered users and check if it has already been used
$AllPeople = "SELECT email, uname FROM login WHERE email = '$email'";
$query = mysqli_query($conn,$AllPeople);

while($row = mysqli_fetch_array($query))
{
    $allEmails = $row['email'];
    $allUnames = $row['uname'];
}

if($allEmails != "")
{
    $message = "That email already exists. You can only have one account per email address.";
}

if($allUnames != "")
{
    $message = "That username has already been taken. Please choose a different one.";
}

if($allEmails === "" && $allUnames === "")
{
    $cost = 10;
    $salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
    $salt = sprintf("$2a$%02d$", $cost) . $salt;
    $hash = crypt($password, $salt);

    mysqli_query($conn, "INSERT INTO login (name, uname, pword, email, lat, lon, it) VALUES ($name, $username, $hash, $email, $lat, $lon, $it");

    $message = "goodtogo";
}

echo json_encode(array("message" => $message, "name" => $name, "it" => $it));

mysqli_close($conn);
?>
  • 写回答

2条回答 默认 最新

  • duanping1920 2013-06-20 12:16
    关注

    1) You forgot single quotes around string data.

    2) the closing bracket for VALUES

    mysqli_query($conn, "INSERT INTO login (name, uname, pword, email, lat, lon, it) 
    VALUES ('$name', '$username', '$hash', '$email', '$lat', '$lon', '$it')");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?