Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- python
- 자바스크립트 API
- 파이썬
- oracle db
- 카카오프로젝트 100
- oracle
- javascript
- 자바스크립트
- 다크웹
- 자바스크립트 jQuery
- 보안뉴스요약
- 자바스크립트 객체
- 카카오프로젝트100
- 보안뉴스한줄요약
- 자바스크립트 기본 문법
- 보안뉴스 한줄요약
- Oracle SQL
- GIT
- 자바스크립트 prototype
- php
- 보안뉴스
- ES6
- 자바스크립트 node
- 자바스크립트 element api
- 깃허브
- 보안뉴스 요약
- numpy
- 오라클
- 랜섬웨어
- 카카오프로젝트
Archives
- Today
- Total
FU11M00N
[ PHP, MYSQL ] php & mysql select문 2 본문

생활코딩의 이고잉 님의 강의를 기반으로 개인 공부용으로 정리한 포스팅입니다.
https://nevertrustbrutus.tistory.com/328
[ PHP,MYSQL ] php & mysql select 연동
생활코딩의 이고잉 님의 강의를 기반으로 개인 공부용으로 정리한 포스팅입니다. - 현재 테이블의 값 현재 컬럼이 3개 존재합니다. 이 값을 php파일로 읽어보겠습니다. - fetch_array 함수 fetch_array
nevertrustbrutus.tistory.com
글과 이어집니다.
- index.php
<?php
$conn = mysqli_connect(
'localhost',
'ID',
'PASSWORD',
'DB이름');
$sql = "SELECT * FROM topic";
$result = mysqli_query($conn, $sql);
$list = '';
while($row = mysqli_fetch_array($result)) {
$list = $list."<li><a href=\"index.php?id={$row['id']}\">{$row['title']}</a></li>";
}
$article = array(
'title'=>'Welcome',
'description'=>'Hello, web'
);
if(isset($_GET['id'])) {
$sql = "SELECT * FROM topic WHERE id={$_GET['id']}";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result);
$article['title'] = $row['title'];
$article['description'] = $row['description'];
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>WEB</title>
</head>
<body>
<h1><a href="index.php">WEB</a></h1>
<ol>
<?=$list?>
</ol>
<a href="create.php">create</a>
<h2><?=$article['title']?></h2>
<?=$article['description']?>
</body>
</html>
- create.php
<?php
$conn = mysqli_connect(
'localhost',
'ID',
'PASSWORD',
'DB이름');
$sql = "SELECT * FROM topic";
$result = mysqli_query($conn, $sql);
$list = '';
while($row = mysqli_fetch_array($result)) {
$list = $list."<li><a href=\"index.php?id={$row['id']}\">{$row['title']}</a></li>";
}
$article = array(
'title'=>'Welcome',
'description'=>'Hello, web'
);
if(isset($_GET['id'])) {
$sql = "SELECT * FROM topic WHERE id={$_GET['id']}";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result);
$article['title'] = $row['title'];
$article['description'] = $row['description'];
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>WEB</title>
</head>
<body>
<h1><a href="index.php">WEB</a></h1>
<ol>
<?=$list?>
</ol>
<form action="process_create.php" method="POST">
<p><input type="text" name="title" placeholder="title"></p>
<p><textarea name="description" placeholder="description"></textarea></p>
<p><input type="submit"></p>
</form>
</body>
</html>

"fu11m00n" 을 클릭하게 되면index.php 페이지에서 fu11m00n의 테이블 값이 바로 출력됩니다.

또한 "create" 를 누르게 되면 index.php 페이지에서 create.php가 출력됩니다.
SUA 정보보안 멘토링에 참여하고 있습니다.
'SUA 정보보안 > php&mysql' 카테고리의 다른 글
[ mysql ] mysql 관계형 데이터베이스. join문 (0) | 2021.02.14 |
---|---|
[ PHP, MYSQL ] php & mysql delete문 (0) | 2021.02.14 |
[ PHP, MYSQL ] php & mysql update문 (0) | 2021.02.14 |
[ PHP, MYSQL ] php & mysql select문 1 (0) | 2021.02.14 |
[ PHP, MYSQL ] php & mysql insert문 (0) | 2021.02.14 |