Zalman
Zalman

Reputation: 11

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

Upvotes: 0

Views: 152

Answers (1)

user2316072
user2316072

Reputation: 111

Use mysql_error() to see if there is any error in your query

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

Upvotes: 1

Related Questions