[英]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.