Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 6th, 2012  |  syntax: None  |  size: 3.69 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Can't update mysql table with $id
  2. <?php          
  3.         include "../php_includes/config.php";
  4.  
  5.         //Conect to the server/database
  6.         if($connect){
  7.             $errors = array();
  8.  
  9.         // check if the 'id' variable is set in URL, and check that it is valid
  10.         if (isset($_GET['id']) && is_numeric($_GET['id']))
  11.         {
  12.         $id = $_GET['id'];
  13.         }
  14.         $query = mysql_query("SELECT * FROM producten WHERE id='$id'");
  15.         while($query_row = mysql_fetch_assoc($query)){
  16.                 $naam_oud = $query_row['naam'];
  17.                 $naam_de_oud = $query_row['naam_de'];
  18.                 $prijs_oud = $query_row['prijs'];
  19.                 $image_oud = $query_row['image'];
  20.         }
  21.         //Display Posts
  22.         if(isset($_POST['naam'],$_POST['naam_de'], $_POST['prijs'])){
  23.             $naam = mysql_real_escape_string(htmlentities($_POST['naam']));
  24.             $naam_de = mysql_real_escape_string(htmlentities($_POST['naam_de']));
  25.             $prijs = mysql_real_escape_string(htmlentities($_POST['prijs']));
  26.             $image = $_FILES['file']['name'];
  27.             $tmp_name = $_FILES['file']['tmp_name'];
  28.  
  29.             if($image){
  30.                 $location = "product_foto/.$image";
  31.                 move_uploaded_file($tmp_name,$location);
  32.  
  33.             }else{
  34.                 $location = $image_oud;
  35.             }
  36.     //Errors
  37.             if(empty($naam)){
  38.                 $errors[] = '<p class="error">Vul een nederlandse product naam in.</p>';
  39.             }
  40.             if(empty($naam_de)){
  41.                 $errors[] = '<p class="error">Vul een duitse product naam in.</p>';
  42.             }
  43.  
  44.             if(empty($prijs)){
  45.                 $errors[] = '<p class="error">Vul een prijs in</p>';
  46.             }
  47.     //Insert Into Database
  48.             if (empty($errors)){
  49.                 $query = "UPDATE producten SET naam='$naam',naam_de='$naam_de',prijs='$prijs', image='$location' WHERE id='$id'";
  50.                     if (mysql_query($query)){
  51.                         header('Location: ../admin/admin.php');die();              
  52.                     } else{
  53.                         $errors[] = '<p class="error">Oeps.. Er is iets verkeerd gegaan. Probeer later opnieuw.</p>';
  54.                     }
  55.     //Errors
  56.             } else{
  57.                 foreach($errors as $error){
  58.                 echo $error;
  59.                 }
  60.             }
  61.         }
  62.         }else{
  63.             echo'<p class="error">Kan geen verbinding maken.<br/> Probeer later opnieuw.</p>';
  64.         }
  65.     ?>
  66.  
  67.  
  68.             <form class="margin" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="POST" enctype='multipart/form-data'>
  69.                 <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/>
  70.                 <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/>
  71.                 <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/>
  72.                 Vorm: euros,centen. zonder euro tekens. (Toevoegingen kunnen na het bedrag geplaatst worden.)<br/><br/>
  73.                 <strong> Foto</strong> <br/><input type="file" name="file"/><br/><br/>
  74.                 <br/><input type="submit" class="button" value="Bewerken" id="submit"/><a href="../admin/admin">Annuleren</a>
  75.             </form>
  76.        
  77. // check if the 'id' variable is set in URL, and check that it is valid
  78.     if (isset($_GET['id']) && is_numeric($_GET['id']))
  79.     {
  80.         $id = $_GET['id'];
  81.     }