【问题标题】:Save profile data based on user id根据用户 ID 保存配置文件数据
【发布时间】:2014-07-13 12:57:44
【问题描述】:

我正在创建个人资料页面,您可以在其中编辑个人资料数据,例如名字、姓氏、出生日期等。 输入根据存储在会话中的用户 ID 填充来自数据库的正确数据。下一步是能够编辑这些字段,并将它们保存在具有会话 ID 的数据库行中。我无法使保存工作。使用下面的代码,我得到一个错误 Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in C:\dev\www\portfolio\profile.php on line 84 line 84包含以下代码。 值 ('$input0101', '$input0102', '$input0103', '$input0104', '$input0105', '$input0106', '$input0107', '$input0108')"); 我希望有人可以帮助我:)!

在输入中存储正确数据的代码。

$id=$_SESSION['id'];
    $connect = mysql_connect("localhost", "root", "root", "portfolio");
    $select_data = mysql_select_db('portfolio', $connect);
    $select_data = mysql_query("SELECT * FROM members WHERE `id`='$id'") or die(mysql_error());
    while($fetch=mysql_fetch_assoc($select_data)) {

        $oImgBox = $dom->getElementById('adminProfilePicture');
        $oImg = $dom->createElement('image');
        $oImg->setAttribute('src',$fetch["profilepic"]);
        $oImgBox->appendChild($oImg);

        $oInput = $dom->getElementById('input0101');
        $oInput->setAttribute('value',$fetch["firstname"]);
        $oInput = $dom->getElementById('input0102');
        $oInput->setAttribute('value',$fetch["lastname"]);
        $oInput = $dom->getElementById('input0103');
        $oInput->setAttribute('value',$fetch["dateofbirth"]);
        $oInput = $dom->getElementById('input0104');
        $oInput->setAttribute('value',$fetch["adress"]);
        $oInput = $dom->getElementById('input0105');
        $oInput->setAttribute('value',$fetch["zipcode"]);
        $oInput = $dom->getElementById('input0106');
        $oInput->setAttribute('value',$fetch["city"]);
        $oInput = $dom->getElementById('input0107');
        $oInput->setAttribute('value',$fetch["country"]);
        $oInput = $dom->getElementById('input0108');
        $oInput->setAttribute('value',$fetch["phone"]);
        $oInput = $dom->getElementById('input0201');
        $oInput->setAttribute('value',$fetch["username"]);
        $oInput = $dom->getElementById('input0202');
        $oInput->setAttribute('value',$fetch["password"]);  
    }

用于将更改的数据保存在数据库中的代码。

        if (isset($_POST["input0101"])) {
        $id=$_SESSION['id'];
        $input0101 = $_POST['input0101'];
        $input0102 = $_POST['input0102'];
        $input0103 = $_POST['input0103'];
        $input0104 = $_POST['input0104'];
        $input0105 = $_POST['input0105'];
        $input0106 = $_POST['input0106'];
        $input0107 = $_POST['input0107'];
        $input0108 = $_POST['input0108'];
        mysqli_query($connect,"INSERT INTO members WHERE `id`='$id' (firstname, lastname, dateofbirth, adress, zipcode, city, country, phone)
        VALUES ('$input0101', '$input0102', '$input0103', '$input0104', '$input0105', '$input0106', '$input0107', '$input0108')");
    }

【问题讨论】:

    标签: php mysql mysqli domdocument


    【解决方案1】:

    您使用 mysql_connect 创建了一个连接,然后将其传递给 mysqli_query。注意 i

    谷歌“mysqli for begineers”和“sql injection”。

    【讨论】:

    • 是的,我看到 xD 我的错误我改变了它,但我仍然收到警告警告:mysql_query() 期望参数 1 是字符串,资源在 C:\dev\www\portfolio\profile 中给出。 php 在第 84 行和第 84 行包含 VALUES ('$input0101', '$input0102', '$input0103', '$input0104', '$input0105', '$input0106', '$input0107', '$input0108') ");
    • mysql_query 获取查询作为第一个参数,而不是连接。所以把 $connect 作为第二个参数。
    • 好的,我改了,但不知何故没有发生任何事情xD
    • 我将 IF 语句移到了 WHILE 中,现在它可以工作了,感谢您的帮助!
    猜你喜欢
    • 2021-09-03
    • 2016-07-08
    • 2016-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-14
    • 2012-08-01
    • 1970-01-01
    相关资源
    最近更新 更多