简体   繁体   English

从2种不同形式获取数据并继续同一表行

[英]Get data from 2 different forms and continue the same table row

Please help me get this done since it's driving me crazy already. 请帮助我完成此操作,因为它已经使我发疯。

I'm new to this whole process so what seems easy for you might be a nightmare for me, and no, google didn't help :( 我是整个过程的新手,所以对您来说似乎容易的事对我来说可能是一场噩梦,不,谷歌没有帮助:(

So, i'm having one mysql table named member with the following structure: 因此,我有一个名为member的mysql表,其结构如下:

  • mem_id mem_id
  • username 用户名
  • password 密码
  • firstname 名字
  • lastname
  • titlu (title) titlu(标题)
  • descriere (description) 描述(描述)
  • joy (integer) 欢乐(整数)
  • comm 通讯

I'm parsing user details using execute.php looking like this: 我正在使用execute.php解析用户详细信息,如下所示:

<?php
session_start();
include('db.php');
$username=$_POST['username'];

$result  =  mysqli_query($db,"SELECT  *  FROM  member  WHERE  username='$username'");
$num_rows  =  mysqli_num_rows($result);

if  ($num_rows)  {
header("location:  index.php?remarks=failed");
}
else
{
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$username=$_POST['username'];
$password=$_POST['password'];
mysqli_query($db,"INSERT  INTO  member(firstname,  lastname,  username,  password)VALUES('$firstname',  '$lastname',  '$username',  '$password')");
header("location:  index.php?remarks=success");
}
?>

Now i have another form that inserts gift details and must continue filling the same row in mysql. 现在我有另一种形式,可以插入礼物详细信息,并且必须继续填充mysql中的同一行。

I've tried the following but no luck: 我尝试了以下方法,但是没有运气:

<?php
session_start();
include('db.php');
$username=$_POST['username'];

$result  =  mysqli_query($db,"SELECT  *  FROM  member  WHERE  username='$username'");
$num_rows  =  mysqli_num_rows($result);

if  ($num_rows)  {
header("location:  index.php?remarks=failed");
}
else
{
$titlu = $_POST['titlu'];
$descriere = $_POST['descriere'];
$joy = $_POST['joy'];
$comm = $_POST['comm'];
$sql = "UPDATE member 
            SET titlu = '".mysql_real_escape_string($_POST[titlu])."'
            SET descriere = '".mysql_real_escape_string($_POST[descriere])."'
            SET joy = '".mysql_real_escape_string($_POST[joy])."'
            SET comm = '".mysql_real_escape_string($_POST[comm])."'
            WHERE username='".mysql_real_escape_string($_POST['username'])."'";
header("location:  welcome.php?remarks=success");
}
?>

Thank you very much for your support! 非常感谢您的支持!

Change your second file to the below code. 将您的第二个文件更改为以下代码。 it will redirect to index.php?remark=failed only if no user exist with the given username 仅当不存在具有给定用户名的用户时,它才会重定向到index.php?remark=failed

 <?php
    session_start();
    include('db.php');
    $username=$_POST['username'];

    $result  =  mysqli_query($db,"SELECT  *  FROM  member  WHERE  username='$username'");
    $num_rows  =  mysqli_num_rows($result);

    if  (!$num_rows)  {
    header("location:  index.php?remarks=failed");
    }
    else
    {
    $titlu = $_POST['titlu'];
    $descriere = $_POST['descriere'];
    $joy = $_POST['joy'];
    $comm = $_POST['comm'];
    $sql = "UPDATE member 
                SET titlu = '".mysql_real_escape_string($_POST[titlu])."',
                descriere = '".mysql_real_escape_string($_POST[descriere])."',
               joy = '".mysql_real_escape_string($_POST[joy])."',
                comm = '".mysql_real_escape_string($_POST[comm])."'
                WHERE username='".mysql_real_escape_string($_POST['username'])."'";
mysqli_query($sql);
    header("location:  welcome.php?remarks=success");
    }
    ?>

I managed to get it done by using: 我设法通过使用完成它:

<?php
    session_start();
    include('db.php');
    include('session.php');

    $res  =  mysqli_query($db,"SELECT * FROM member where mem_id=$loggedin_id");    
    $num_rows  =  mysqli_num_rows($res);

    if  (!$num_rows)  {
        header("location:  welcome.php?remarks=failed");
    }
    else
    {
    $titlu = $_POST['titlu'];
    $descriere = $_POST['descriere'];
    $joy = $_POST['joy'];
    $comm = $_POST['comm'];

mysqli_query($db,"UPDATE member 
               SET titlu = '$titlu',
               descriere = ' $descriere ',
               joy = '$joy',
               comm = '$comm'
               where mem_id=$loggedin_id");
    header("location:  welcome.php?remarks=success");
    }
    ?>

But now, i need help with the next step: 但是现在,我需要下一步的帮助:

I need to get all the data from the database,except mine, as a logged in user, in a html table. 我需要以html表的登录用户身份从数据库中获取所有数据,但我的数据库除外。 I'm trying the following but brings back nothing: 我正在尝试以下操作,但没有带来任何回报:

<? 
$result = mysql_query($db,"SELECT * FROM member")

or die(mysql_error());

echo "<table border='1' cellpadding='10'>";

echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>";

while($row = mysql_fetch_array( $result )) {

echo "<tr>";

echo '<td>' . $row['mem_id'] . '</td>';

echo '<td>' . $row['firstname'] . '</td>';

echo '<td>' . $row['lastname'] . '</td>';

echo "</tr>";

}



// close table>

echo "</table>";

?>

Any ideas? 有任何想法吗?

Thank you very much! 非常感谢你!

you can use mysqli_insert_id get last id insert. 您可以使用mysqli_insert_id获取最后的ID插入。 Then update with id. 然后使用ID更新。

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

相关问题 连续打印同一张表中的不同数据 - print different data from same table in a row 如何将同一表中不同行的数据连接在一行中? - How can i concatenate data different row from same table in one row? 如何从另一个表中获取值并将相同的数据插入到不同表中的特定行 - How to Fetch value from another table and INSERT the same data to specific row in a different table 从中获取数据 <td> 在由行ID指定的同一表行上执行计算 - Get data from <td> on the same table row specified by row id and perform computation 如何从同一张表中获取相关行? - How to get related row from same table? 有没有办法从 2 个不同的 forms 和 INSERT 插入数据到列中的 1 行? - Is there a way to INSERT data from 2 DIFFERENT forms and INSERT into 1 row in column? 如何从表中获取所有数据,如果在同一列中重复相同的值,则该行应计数一次? - How to get get all the data from table and if same value repeated in one column that row should count once? PHP - 从同一行的不同列中获取和比较行值 - PHP - Get and compare row value from a different column for the same row php - html:表中同一列的每一行中的不同数据 - php - html: Different data in each row of a the same column in a table 从同一个表中获取不同的数据 - Fetch different data from the same table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM