dtpwra8456 2014-04-26 00:05
浏览 17

更新查询不更新表

I have a user data profile that I want to update when a user has filled out a form. When the update query is run values are being passed to the PHP script but not being changed in the table.

HTML of form:

    echo "<br />";
    echo "From this page you can change your profile details.";
    echo "<br />";
    echo "<br />";
    echo "<form id='edit' action='../scripts/editscript.php' method='post' accept-charset='UTF-8'>";
    echo "<label for='firstname'>First Name:</label>";
    echo "<input type='text' id='firstname' name='firstname' />";
    echo "<br />";
    echo "<label for='lastname'>Last Name:</label>";
    echo "<input type='text' id='lastname' name='lastname' />";
    echo "<br />";
    echo "<label for='username'>User Name:</label>";
    echo "<input type='text' id='username' name='username' />";
    echo "<br />";
    echo "<label for='password'>Password:</label>";
    echo "<input type='password' id='password' name='password' />";
    echo "<br />";
    echo "<label for='passwordconfirm'>Confirm Password:</label>";
    echo "<input type='password' id='passwordconfirm' name='passwordconfirm' />";
    echo "<br />";
    echo "<label for='email'>E-Mail:</label>";
    echo "<input type='email' id='email' name='email' />";
    echo "<br />";
    echo "<label for='like'>Something you like:</label>";
    echo "<input type='text' id='like' name='like' />";
    echo "<br />";
    echo "<label for='dislike'>Something you dislike</label>";
    echo "<input type='text' id='dislike' name='dislike' />";
    echo "<br />";
    echo "<label for='fact'>A fun fact about yourself:</label>";
    echo "<input type='text' id='fact' name='fact' />";
    echo "<br />";
    echo "<label for='allow'>Do you want other people to see parts of your profile:</label>";
    echo "<input type='radio' name='allow' value='yes' /> Yes";
    echo "<input type='radio' name='allow' value='no' /> No";
    echo "<br />";
    echo "<br />";
    echo "<input type='submit' name='submit' value='Confirm' />";
    echo "</form>";

PHP script:

<?PHP
session_start();
$time = time();
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
$salt = substr(base64_encode(openssl_random_pseudo_bytes(17)),0,22);
$salt = str_replace("+",".",$salt);
$salt = '$2a$08$' . $salt;
$password = crypt($_POST['password'], $salt);
$email = $_POST['email'];
$like = $_POST['like'];
$dislike = $_POST['dislike'];
$fact = $_POST['fact'];
$allow = $_POST['allow'];
$UID = $_SESSION['user']['UID'];
if ($allow == 'yes') {
    $allowvalue = 1;
} else {
    $allowvalue = 0;
};
$con = mysqli_connect('localhost','//db_username','//db_pass','//table');
if (mysqli_connect_errno($con)) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query = "UPDATE users SET firstname = '" . $firstname . "',
lastname = '" . $lastname . "',
username = '" . $username . "',
password = '" . $password . "',
email = '" . $email . "',
like = '" . $like . "',
dislike = '" . $dislike . "',
fact = '" . $fact . "',
allowview = " . $allowvalue . " WHERE UID = " . $UID . "";
mysqli_query($con,$query);
mysqli_close($con);
?>

I really don't get why this isn't going as expected. Any help is appreciated. :)

  • 写回答

3条回答 默认 最新

  • doudui5753 2014-04-26 00:09
    关注

    do a

    var_dump($_SESSION['user']['UID']);
    

    most probably the id does not match the id in the db

    评论

报告相同问题?

悬赏问题

  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染