- Can't update mysql table with $id
- <?php
- include "../php_includes/config.php";
- //Conect to the server/database
- if($connect){
- $errors = array();
- // check if the 'id' variable is set in URL, and check that it is valid
- if (isset($_GET['id']) && is_numeric($_GET['id']))
- {
- $id = $_GET['id'];
- }
- $query = mysql_query("SELECT * FROM producten WHERE id='$id'");
- while($query_row = mysql_fetch_assoc($query)){
- $naam_oud = $query_row['naam'];
- $naam_de_oud = $query_row['naam_de'];
- $prijs_oud = $query_row['prijs'];
- $image_oud = $query_row['image'];
- }
- //Display Posts
- if(isset($_POST['naam'],$_POST['naam_de'], $_POST['prijs'])){
- $naam = mysql_real_escape_string(htmlentities($_POST['naam']));
- $naam_de = mysql_real_escape_string(htmlentities($_POST['naam_de']));
- $prijs = mysql_real_escape_string(htmlentities($_POST['prijs']));
- $image = $_FILES['file']['name'];
- $tmp_name = $_FILES['file']['tmp_name'];
- if($image){
- $location = "product_foto/.$image";
- move_uploaded_file($tmp_name,$location);
- }else{
- $location = $image_oud;
- }
- //Errors
- if(empty($naam)){
- $errors[] = '<p class="error">Vul een nederlandse product naam in.</p>';
- }
- if(empty($naam_de)){
- $errors[] = '<p class="error">Vul een duitse product naam in.</p>';
- }
- if(empty($prijs)){
- $errors[] = '<p class="error">Vul een prijs in</p>';
- }
- //Insert Into Database
- if (empty($errors)){
- $query = "UPDATE producten SET naam='$naam',naam_de='$naam_de',prijs='$prijs', image='$location' WHERE id='$id'";
- if (mysql_query($query)){
- header('Location: ../admin/admin.php');die();
- } else{
- $errors[] = '<p class="error">Oeps.. Er is iets verkeerd gegaan. Probeer later opnieuw.</p>';
- }
- //Errors
- } else{
- foreach($errors as $error){
- echo $error;
- }
- }
- }
- }else{
- echo'<p class="error">Kan geen verbinding maken.<br/> Probeer later opnieuw.</p>';
- }
- ?>
- <form class="margin" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="POST" enctype='multipart/form-data'>
- <strong>Product naam Nederlands</strong> <br/> <input value="<?php echo $naam_oud;?> " id="focus" type="text" class="input_field" name="naam" maxlength="150" style="width:600px;"><br/><br/>
- <strong>Product naam Duits</strong> <br/> <input id="focus" type="text" class="input_field" value="<?php echo $naam_de_oud;?>"name="naam_de" maxlength="150" style="width:600px;"><br/><br/>
- <strong> Prijs</strong> <br/> <input id="focus" type="text" class="input_field" name="prijs" value="<?php echo $prijs_oud;?> "maxlength="150" style="width:600px;"><br/>
- Vorm: euros,centen. zonder euro tekens. (Toevoegingen kunnen na het bedrag geplaatst worden.)<br/><br/>
- <strong> Foto</strong> <br/><input type="file" name="file"/><br/><br/>
- <br/><input type="submit" class="button" value="Bewerken" id="submit"/><a href="../admin/admin">Annuleren</a>
- </form>
- // check if the 'id' variable is set in URL, and check that it is valid
- if (isset($_GET['id']) && is_numeric($_GET['id']))
- {
- $id = $_GET['id'];
- }