使用SQL查询更新用户信息

时间:2015-01-09 02:16:10

标签: php mysql sql mysqli

更新了代码,在输入信息并单击提交按钮以运行此代码后,它会返回到帐户页面,但不会更新数据库:

<font face="ClearSans-Thin">
<font color="lightgray">

<?php

include 'editaccount.php';
include 'connection.php';
?>

<center>
<?php
if (isset($_POST['uregsubmit'])) {
    $firstname = $_POST['ufirstname'];
    $lastname = $_POST['ulastname'];
    $email = $_POST['uemail'];
    $dob = $_POST['udob'];
    $user = $_POST['uregisterusername'];

    $pass = $_POST['uregisterpassword'];

    }

    //the query
$query = "UPDATE Users SET FirstName='$firstname', LastName='$lastname' WHERE Username='$user'";
//execute the query
$result = mysqli_query($connection, $query)
or die("Error: ".mysqli_error($connection));
//check and see if any data returned





?>
</center>

2 个答案:

答案 0 :(得分:0)

在WHERE

之前有一个额外的逗号

答案 1 :(得分:0)

在if语句

中写入sql查询
<?php
if (isset($_POST['uregsubmit'])) {
    $firstname = $_POST['ufirstname'];
    $lastname = $_POST['ulastname'];
    $email = $_POST['uemail'];
    $dob = $_POST['udob'];
    $user = $_POST['uregisterusername'];
    $pass = $_POST['uregisterpassword'];

    //the query
    $query = "UPDATE Users SET FirstName='$firstname', LastName='$lastname' WHERE Username='$user'";
    //execute the query
    $result = mysqli_query($connection, $query)
    or die("Error: ".mysqli_error($connection));
    //check and see if any data returned
}
?>