Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $model = "";
- $year = "";
- $price = "";
- $img = "";
- if ( $_POST ) {
- $model = $_POST['model'];
- $year = $_POST['year'];
- $price = $_POST['price'];
- $file = $_FILES['img'];
- $file_name = $_FILES['img']['name'];
- $file_temp = $_FILES['img']['tmp_name'];
- $file_type = $_FILES['img']['type'];
- $connection = new PDO('mysql:host=localhost;dbname=cars', "newuser", "1234");
- $sql = "INSERT INTO cars (model,year,price) VALUES (?,?,?)";
- $connection->prepare($sql)->execute([$model, $year, $price]);
- $id = $connection->lastInsertId();
- $result = move_uploaded_file( $file_temp, "images/".$id.".jpg" );
- // print_r( $_POST );
- echo "<b style='color:green'>Благодаря!</b><br><Br>";
- }
- // Още полета
- // https://www.w3schools.com/html/html_form_input_types.asp
- ?>
- <form action="form2.php" method="post" enctype="multipart/form-data">
- <!-- Text -->
- <label for="text">Year:</label><br>
- <input id="text" type="text" name="year" value="<?= $year ?>">
- <br><br>
- <label for="text">Model:</label><br>
- <input id="text" type="text" name="model" value="<?= $model ?>">
- <br><br>
- <label for="text">Price:</label><br>
- <input id="text" type="text" name="price" value="<?= $price ?>">
- <br><br>
- <label for="text">Image:</label><br>
- <input id="text" type="file" name="img" >
- <br><br>
- <!-- Submit -->
- <br><br>
- <input type="submit" name="submit" value="Submit">
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement