Jump to content

BartWilke

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by BartWilke

  1. Hi all,

     

    I got a error when trying to upload to database. Perhaps someone can help me ?

     

     

    Error:

     

    ERROR: Could not able to execute INSERT INTO `Puzzle` (`NamePuzzle`, `image`) VALUES ('', '').

     

    HTML Code:

     

    <form action="..upload.php" method="post" enctype="multipart/form-data">

    Image: <input type="file" name="image" id="take-picture"><br>
    Name Puzzle: <input type="text" name="NamePuzzle"><br>
    <br>
    <input type="submit" value="Upload Puzzle" name="submit">
    </form>
    PHP Code:
    <?php
    include "conn.php";
    $target_dir = "../uploads/";
    $target_file = $target_dir . basename($_FILES["picture"]["name"]);
    $uploadOk = 1;
    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
    // Check if image file is a actual image or fake image
    if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["picture"]["tmp_name"]);
    if($check !== false) {
    echo "File is an image - " . $check["mime"] . ".";
    $uploadOk = 1;
    } else {
    echo "File is not an image.";
    $uploadOk = 0;
    }
    }
    // Check if file already exists
    if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
    }
    // Check file size
    if ($_FILES["picture"]["size"] > 500000) {
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
    }
    // Allow certain file formats
    if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
    && $imageFileType != "gif" ) {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
    }
    // Check if $uploadOk is set to 0 by an error
    if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
    // if everything is ok, try to upload file
    } else {
    if (move_uploaded_file($_FILES["picture"]["tmp_name"], $target_file)) {
    echo "The file ". basename( $_FILES["picture"]["name"]). " has been uploaded.";
    } else {
    echo "Sorry, there was an error uploading your file.";
    }
    }
    // Escape user inputs for security
    $image = mysqli_real_escape_string($link, $_POST['image']);
    $NamePuzzle = mysqli_real_escape_string($link, $_POST['NamePuzzle']);
    // attempt insert query execution
    $sql = "INSERT INTO `Puzzle` (`NamePuzzle`, `image`) VALUES ('$image', '$NamePuzzle')";
    if(mysqli_query($link, $sql)){
    echo "Records added successfully.";
    } else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
    }
    // close connection
    mysqli_close($link);
    ?>
  2. Thanks for your help! ill have a look into that :)

     

    as for now i managed to make it work just to move all square 1 px to the left and one down..

     

    <script>
    var can = document.getElementById('blokjes');
    var ctx = can.getContext('2d');
    var pattern = document.createElement('canvas');
    pattern.width = 12;
    pattern.height = 12;
    var pctx = pattern.getContext('2d');
    pctx.fillStyle = "rgb(0, 0, 0)";
    pctx.fillRect(0,0,5,5);
    pctx.fillRect(6,6,5,5);
    pctx.fillRect(0,6,5,5);
    pctx.fillRect(6,0,5,5);
    var pattern = ctx.createPattern(pattern, "repeat");
    ctx.beginPath();
    ctx.moveTo(0, 0);
    ctx.lineTo(500, 0);
    ctx.lineTo(500, 500);
    ctx.lineTo(0, 500);
    ctx.closePath();
    ctx.fillStyle = pattern;
    ctx.fill();
    </script>
  3. Hi all,

     

    I'm trying to get a grid of black squares but need to make a border that is transparant so i can see the squares instead of just one big black square..

     

    here is my code:

     

    <script>
    var can = document.getElementById('blokjes');
    var ctx = can.getContext('2d');
    var pattern = document.createElement('canvas');
    pattern.width = 20;
    pattern.height = 20;
    var pctx = pattern.getContext('2d');
    pctx.fillStyle = "rgb(0, 0, 0)";
    pctx.fillRect(0,0,10,10);
    pctx.fillRect(10,10,10,10);
    pctx.fillRect(0,10,10,10);
    pctx.fillRect(10,0,10,10);
    var pattern = ctx.createPattern(pattern, "repeat");
    ctx.beginPath();
    ctx.moveTo(0, 0);
    ctx.lineTo(500, 0);
    ctx.lineTo(500, 500);
    ctx.lineTo(0, 500);
    ctx.closePath();
    ctx.fillStyle = pattern;
    ctx.fill();
    </script>
×
×
  • Create New...