Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 KB | None | 0 0
  1.  
  2. <?php
  3. $servername = "localhost";
  4. $username = "BAUM";
  5. $password = "HAUS";
  6. $dbname = "BAUMHAUS";
  7.  
  8. print_r($_POST);
  9.  
  10. if (isset($_POST['update'])){ // prüfen ob formular übermittelt
  11.    $ID = $_POST['id'];
  12.  
  13.    if ($ID > 0) {
  14.     // Create connection
  15.     $conn = mysqli_connect($servername, $username, $password, $dbname);
  16.     // Check connection
  17.     if (!$conn)
  18.         die("Connection failed: " . mysqli_connect_error());
  19.            
  20.     $id = $_POST['id'];
  21.     $title = $_POST['title'];
  22.     $content = $_POST['content'];
  23.     $img = $_POST['img'];
  24.     $img2 = $_POST['img2'];    
  25.        
  26.     if (filter_var($content, FILTER_VALIDATE_EMAIL)) {
  27.        
  28.         //entweder '$variable' oder '".$variable."' beides möglich liest du aus einem array aus geht nur die zweite variante
  29.            
  30.         $sql = "UPDATE texte
  31.         SET
  32.         id='".$id."',
  33.         title='".$title."',
  34.         content='".$content."',
  35.         img='".$img."',
  36.         img2='".$img2."',
  37.        
  38.         WHERE id='$id' LIMIT 1";
  39.  
  40.         if (mysqli_query($conn, $sql)) {
  41.             echo "Record updated successfully";
  42.         } else {
  43.             echo "Error updating record: " . mysqli_error($conn);
  44.         }      
  45.     } else
  46.    
  47.     mysqli_close($conn);
  48.    } else {
  49.        echo "ID ERROR";
  50.    }
  51.    
  52. }
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement