Z góry dziękuję za pomoc
1.FORM
<?php //1. polaczenie z baza danych //polaczenie z baza danych + ustawienie kodowania na utf8 $dbhost = "localhost"; $dbuser = "root"; $dbpass = "3edcvfr4"; $dbname = "dw_bookstore"; $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); //sprawdzenie polaczenia if (mysqli_connect_errno()) { } //zmaiana znako na utf8 if (!mysqli_set_charset($connection, "utf8")) { } else { } ?> <?php // get ID @$id = $_GET['id']; @$query = "SELECT * FROM photographs WHERE id = '$id' "; //pokazuje co zostalo zmienione $result = mysqli_query($connection, $query); if (!$result) { } $row = mysqli_fetch_array($result); ?> <?php //if (!id) { // redirect_to("costam.php"); // } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Update Form</title> </head> <body> <form action="database_update_action.php" method="post" enctype="multipart/form-data" name="form1" target="_blank"> <table border="0" cellspacing="2" cellpadding="2"> <tr> <td>ID:</td> </tr> <tr> <td>filename</td> <td><label for="filename"></label> </tr> <tr> <td>type</td> <td><label for="type"></label> </tr> <tr> <td>size</td> <td><label for="size"></label> </tr> <tr> <td>caption</td> <td><label for="caption"></label> </tr> <tr> <td>caption_2</td> <td><label for="caption_2"></label> </tr> <tr> <td>txt</td> <td><label for="txt"></label> </tr> <tr> <td> </td> <td><input type="submit" name="submit" id="submit" value="update"></td> </tr> </table> </form> <?php //4. release returned data //mysqli_free_result($result); ?> </body> </html> <?php // 5. Zamkniecie bazy mysqli_close($connection); ?>
2. Action
<?php //1. polaczenie z baza danych //polaczenie z baza danych + ustawienie kodowania na utf8 $dbhost = "localhost"; $dbuser = "root"; $dbpass = "3edcvfr4"; $dbname = "dw_bookstore"; $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); //sprawdzenie polaczenia if (mysqli_connect_errno()) { } //zmaiana znako na utf8 if (!mysqli_set_charset($connection, "utf8")) { } else { } ?> <?php //2. przeslanie zdjecia wraz z danymi @$path = $_FILES["file"]["name"]; @$type = $_FILES["file"]["type"]; @$size = $_FILES["file"]["size"]; $id = $_POST["id"]; $caption = $_POST["caption"]; $caption_2 = $_POST["caption_2"]; $txt = $_POST["txt"]; // przyklad - by moc wpisac 'costam' - tylko txt, nie "file" i "int" $caption = mysqli_real_escape_string($connection, $caption); $caption_2 = mysqli_real_escape_string($connection, $caption_2); $txt = mysqli_real_escape_string($connection, $txt); // 2. Perform database query $query = "UPDATE photographs SET "; $query .= "filename = '{$path}', "; $query .= "size = '{$size}', "; $query .= "type = '{$type}', "; $query .= "caption = '{$caption}', "; $query .= "caption_2 = '{$caption_2}', "; $query .= "txt = '{$txt}' "; $query .= "WHERE id = {$id}"; //$query = "INSERT INTO photographs ("; //$query .= " filename, type, size, caption, caption_2, txt"; //$query .= ") VALUES ("; //$query .= " '{$path}', '{$type}', '{$size}', '{$caption}', '{$caption_2}', '{$txt}'"; //$query .= ")"; $result = mysqli_query($connection, $query); if ($result) { // Success // redirect_to("somepage.php"); } else { // Failure // $message = "Subject creation failed"; if (((@$_FILES["file"]["type"] == "image/gif") || (@$_FILES["file"]["type"] == "image/jpeg") || (@$_FILES["file"]["type"] == "image/JPEG") || (@$_FILES["file"]["type"] == "image/jpg") || (@$_FILES["file"]["type"] == "image/png") || (@$_FILES["file"]["type"] == "image/pjpeg")) && (@$_FILES["file"]["size"] < 600000)) { if ($_FILES["file"]["error"] > 0) { } else { } else{ } } } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Update Action</title> </head> <body> </body> </html> <?php // 5. Zamkniecie polaczenia mysqli_close($connection); ?>