简体   繁体   English

mysqli更新带有额外的查询

[英]mysqli Update with extra query

At first I have to enter two Accountnames in the website. 首先,我必须在网站中输入两个帐户名。

My tablename is 'account'. 我的表名是“帐户”。

The rows are id, username and recruiter. 这些行是ID,用户名和招聘者。
The lines are 线是
7, Janis, 0 7,贾尼斯,0
and
4, testlol, 0. 4,testlol,0。

I want to 'connect' two users. 我想“连接”两个用户。 In the first line - the line of Janis - have to change his 'recruiter' into the value of the other user. 在第一行(Janis行)中,必须将其“招聘者”更改为其他用户的价值。

So the result should looks like: 因此结果应如下所示:

7 | 7 | Janis | 贾尼斯| 4 4
and
4 | 4 | testlol | 睾丸| 7 7

... ...

In my php script I wrote 在我的PHP脚本中,我写了

<?php
$servername = "localhost";
$username = "name";
$password = "test";
$dbname = "db";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql1 = "UPDATE account SET recruiter=??? WHERE username=\"" . $_POST["account1"] . "\"";

if ($conn->query($sql) === TRUE) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . $conn->error;
}

$conn->close();
?> 

What do I have to write instead of the ??? 我必须写些什么而不是??? for updating it with the other user's id? 用其他用户的ID更新它?

It's from this form: 它来自以下形式:

<form action="handler.php" method="post" >
    <p>Account Nr.1:</p><input class="input" type="text" name="account1" value="">
    <p>Account Nr.2:</p><input class="input" type="text" name="account2" value="">
    <p></p><input class="button" type="submit" name="submit" value="Bestätigen"> 
</form>

This should be what you're looking for below. 这应该是您在下面查找的内容。 Although, it's hard to tell from you post what exactly you want. 虽然,很难从您的帖子中得知您到底想要什么。 If I'm following correctly, you want to switch the recruiter value to other recruiter? 如果我正确遵循,您想将招聘人员的价值转换为其他招聘人员吗? If so, this should work: 如果是这样,这应该起作用:

$sql1 = "UPDATE account SET recruiter = $_POST["account2"] WHERE username = $_POST["account1"]";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM