簡體   English   中英

根據用戶ID保存配置文件數據

[英]Save profile data based on user id

我正在個人資料頁面上工作,您將可以在其中編輯您的個人資料數據,例如名字,姓氏,出生日期等。輸入中會根據數據庫中存儲的用戶ID填充來自數據庫的正確數據。會話。 下一步是能夠編輯這些字段,並將它們保存在具有會話ID的數據庫行中。 我無法進行保存工作。 在下面的代碼下面,我得到一個錯誤警告:mysqli_query()期望參數1為mysqli,在84行的C:\\ dev \\ www \\ portfolio \\ profile.php中給出的資源包含以下代碼。 VALUES('$ 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')");
    }

您使用mysql_connect創建了一個連接,然后將其傳遞給mysqli_query。 注意i

Google“初學者的mysqli”和“ sql注入”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM