如何从一个表插入到花药中获取id? [英] How do I grab id from one table insert into anther?

查看:72
本文介绍了如何从一个表插入到花药中获取id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将与用户名匹配的ID插入到信息表中。

[帐户表]

[信息表]

infosubmit.php

I want the id that matches username to be inserted into information table.
[Account Table]
[Information Table]
infosubmit.php

<?php
include "connection.php";
session_start();
$username = $_SESSION['username'];
$id = mysqli_query(" SELECT `id` FROM `account` WHERE `username` = '$username' limit 1");
$id = mysqli_real_escape_string($conn, $id);
$first = $_POST['first'];
$last = $_POST['last'];
$birthday =$_POST['birthday'];
$address = $_POST['address1'];
$weight = $_POST['weight'];
$height = $_POST['height'];
$sql = " INSERT INTO `information` (`id`, `first`, `last`, `birthday`, `address`, `weight`, `height`) 
							VALUES ('$id', '$first', '$last', '$birthday', '$address', '$weight', '$height') ";
if ($conn->query($sql) === TRUE) {
    $message = "New record created successfully";
} else {
    $message = "Error: " . $sql . "<br>" . $conn->error;
}
?>
<!DOCTYPE html>
	<head>
		<link rel="apple-touch-icon" sizes="180x180" href="images/favicons/apple-touch-icon.png">
		<link rel="icon" type="image/png" href="images/favicons/favicon-32x32.png" sizes="32x32">
		<link rel="icon" type="image/png" href="images/favicons/favicon-16x16.png" sizes="16x16">
		<link rel="manifest" href="manifest.json">
		<link rel="mask-icon" href="images/favicons/safari-pinned-tab.svg" color="#741372">
		<meta name="apple-mobile-web-app-title" content="Medical Database">
		<meta name="application-name" content="Medical Database">
		<meta name="theme-color" content="#741372">
		<link rel="stylesheet" href="style/main.css" type="text/css">
		<title>Information-Submitted</title>
	</head>
	<body>
		<menu>
			<ul>
				<li><a href="logout.php">Log Out</a></li>
			</ul>
		</menu>
		<?php echo $id; ?>
		<br><?php echo $message; ?>
	</body>
</html>





我有什么试过:



在网上看,用



What I have tried:

looking online, added more php with

mysqli_real_escape_string

添加更多php

mysqli_query

推荐答案

用户名 =
username =


_SESSION [ ' username'];
_SESSION['username'];


id = mysqli_query( SELECT`id` FROM`count` WHERE`username` ='
id = mysqli_query(" SELECT `id` FROM `account` WHERE `username` = '


这篇关于如何从一个表插入到花药中获取id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆