MySQL 실습 1
실습환경으로 codeanywhere를 쓰고 계신 분은 아래 영상의 13:30 즈음의 영상의 코드를 다음와 같이 바꿔서 사용하시면 됩니다. 비밀번호를 지정하지 않으면 됩니다. $conn = mysqli_connect('localhost', 'root', '');
MySQL 실습 2
MySQL 실습 3
MySQL 실습 4
MySQL 실습 5
index.php
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 31 32 33 34 35 36 37 38 39 40 41 42 43 | <?php $conn = mysqli_connect( "localhost" , "root" , 111111); mysqli_select_db( $conn , "opentutorials" ); $result = mysqli_query( $conn , "SELECT * FROM topic" ); ?> <!DOCTYPE html> <html> <head> <meta charset= "utf-8" > </head> <body id= "target" > <header> <img src= "https://s3.ap-northeast-2.amazonaws.com/opentutorials-user-file/course/94.png" alt= "생활코딩" > </header> <nav> <ol> <?php while ( $row = mysqli_fetch_assoc( $result )){ } ?> </ol> </nav> <div id= "control" > <input type= "button" value= "white" onclick= "document.getElementById('target').className='white'" /> <input type= "button" value= "black" onclick= "document.getElementById('target').className='black'" /> </div> <article> <?php if ( empty ( $_GET [ 'id' ]) === false ) { $sql = 'SELECT * FROM topic WHERE id=' . $_GET [ 'id' ]; $result = mysqli_query( $conn , $sql ); $row = mysqli_fetch_assoc( $result ); echo '<h2>' . $row [ 'title' ]. '</h2>' ; echo $row [ 'description' ]; } ?> </article> </body> </html> |
write.php
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | <?php $conn = mysqli_connect( "localhost" , "root" , 111111); mysqli_select_db( $conn , "opentutorials" ); $result = mysqli_query( $conn , "SELECT * FROM topic" ); ?> <!DOCTYPE html> <html> <head> <meta charset= "utf-8" > </head> <body id= "target" > <header> <img src= "https://s3.ap-northeast-2.amazonaws.com/opentutorials-user-file/course/94.png" alt= "생활코딩" > </header> <nav> <ol> <?php while ( $row = mysqli_fetch_assoc( $result )){ } ?> </ol> </nav> <div id= "control" > <input type= "button" value= "white" onclick= "document.getElementById('target').className='white'" /> <input type= "button" value= "black" onclick= "document.getElementById('target').className='black'" /> </div> <article> <form action= "process.php" method= "post" > <p> 제목 : <input type= "text" name= "title" > </p> <p> 작성자 : <input type= "text" name= "author" > </p> <p> 본문 : <textarea name= "description" ></textarea> </p> <input type= "submit" name= "name" > </form> </article> </body> </html> |
process.php
1 2 3 4 5 6 7 | <?php $conn = mysqli_connect( "localhost" , "root" , 111111); mysqli_select_db( $conn , "opentutorials" ); $sql = "INSERT INTO topic (title,description,author,created) VALUES('" . $_POST ['title ']."' , '".$_POST[' description ']."' , '".$_POST[' author ']."' , now())"; $result = mysqli_query( $conn , $sql ); ?> |
style.css
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 31 32 33 34 35 | body. white { background-color : white ; color : black ; } body. black { background-color : black ; color : white ; } header{ border-bottom : 1px solid gray ; padding : 20px ; } nav { border-right : 1px solid gray ; width : 200px ; height : 600px ; float : left ; } nav ol{ list-style : none ; padding : 0 ; } article{ float : left ; padding : 20px ; width : 500px ; } #control{ float : right ; } header img{ float : right ; height : 100px ; } |