我正在个人资料页面上工作,您将可以在其中编辑个人资料数据,例如名字,姓氏,出生日期等。
这些输入将根据会话中存储的用户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注入”。
关于php - 根据用户ID保存配置文件数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24722941/