简体   繁体   中英

MySQL update isn't updating

<?php
require("header.inc.php");
?>

<?php
if (isLoggedIn()) {
    if (isset($_POST['CKey_Button'])) {
        if (!isset($_POST['CKey'])) {
            die("Error: The Character Key field was not set.");
        }
    }

    $CKey = $_POST['CKey_Button'];

    mysql_select_db("samp");

    $query = mysql_query("SELECT `id` FROM `players` WHERE `CharacterKey` = '" . mysql_real_escape_string($_POST['CKey']) . "' LIMIT 1");

    if (mysql_num_rows($query)) {
        mysql_select_db("ucp");
        mysql_query("UPDATE `users` SET `CharacterID` = '" . $CKey . "' WHERE `name` = '" . $user['name'] . "'");
        header("./Dashboard.php");
        exit;
    }
    else {
        header("./index.php");
        exit;
    }
}
else {
    header("./index.php");
    exit;   
}
?>

That is the code but it isn't updating and it just a blank screen, does anyone know why this could be happening(I have just started coding php so be nice if it's a newbie error).

EDIT: I have fixed it I was using $CKey as the button and not the actual key, hope this makes sense, I also changed = '" . $CKey . "' to = " . $CKey

使用mysql_error()查看查询中是否有错误

mysql_query($query) or die ('Error updating database: '.mysql_error());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM