mwktar Posted October 29, 2017 Share Posted October 29, 2017 Hi guys - the only issue i'm having so far id the storing of "Creation Name" in the sql database - it either stores ARRAY or nothing at in (in the example below). I'm "shoe horning" my awful php in with a Dropzone.js script. The file name and creation date are both being stored. The form is: <form action="?add" class="dropzone" method = "post" > <div class="dz-message needsclick"> <strong>Drag an image of your creation here to upload!</strong><br /> <span class="note needsclick">OR click to upload a file</span> </div> </div> <div style="margin:10px 0px 0px 0px;"> Creation Name: <input type="text" name="creationname"> Number of Bricks: <input type="number" name="bricks"> Difficulty: <input type="range" name="difficulty" min="0" max="10"> Creator Name: <input type="text" name="user"> Time taken: Tags: </div> <input type="submit" value="Submit" > Which is then handled by this PHP if (isset($_GET['add'])) include 'dbconfig.php'; { if(!empty($_FILES)){ $creationname= mysqli_real_escape_string($conn, $_POST['creationname']); $bricks=['bricks']; $difficulty=['difficulty']; $creator=['user']; $upload_dir = "uploads/"; $fileName = $_FILES['file']['name']; $uploaded_file = $upload_dir.$fileName; if(move_uploaded_file($_FILES['file']['tmp_name'],$uploaded_file)){ $mysql_insert = "INSERT INTO uploads (file_name, upload_time, name, bricks, difficulty)VALUES('".$fileName."','".date("Y-m-d H:i:s")."','".$creationname."','".$bricks."','".$difficulty."')"; mysqli_query($conn, $mysql_insert) or die("database error:". mysqli_error($conn)); } } } Quote Link to comment Share on other sites More sharing options...
mwktar Posted October 29, 2017 Author Share Posted October 29, 2017 Sorted this by being less of an idiot if anyone is wondering! Quote Link to comment Share on other sites More sharing options...
Barand Posted October 29, 2017 Share Posted October 29, 2017 How much less? For example, are you now using prepared statements for the insert? Have you redefined "upload_time" as column type "TIMESTAMP DEFAULT CURRENT_TIMESTAMP" and omitted it from the query? Quote Link to comment Share on other sites More sharing options...
mwktar Posted October 29, 2017 Author Share Posted October 29, 2017 apparently not less enough! It was the dropzone js interfering with the php form - I've managed to find a work around (that isn't really a solution) - for some reason if I select the image for upload THEN enter the data, none of it is passed to the DB. If i enter then data THEN the image all gets passed along - trying to solve now :/ Quote Link to comment Share on other sites More sharing options...
mwktar Posted October 29, 2017 Author Share Posted October 29, 2017 Actually I lied - when the image is being uploaded first the difficulty range is still being stored, only the name and bricks are being passed over - current work here: //handle submissions - save image and insert data into my db if (isset($_POST['add'])) include 'dbconfig.php'; { if(!empty($_FILES)){ $creationname= $_POST['creationname']; $bricks=$_POST['bricks']; $difficulty=$_POST['difficulty']; $creator=$_POST['user']; $upload_dir = "uploads/"; $fileName = $_FILES['file']['name']; $uploaded_file = $upload_dir.$fileName; if(move_uploaded_file($_FILES['file']['tmp_name'],$uploaded_file)){ $mysql_insert = "INSERT INTO uploads (file_name, upload_time, name, bricks, difficulty)VALUES('".$fileName."','".date("Y-m-d H:i:s")."','".$creationname."','".$bricks."','".$difficulty."')"; mysqli_query($conn, $mysql_insert) or die("database error:". mysqli_error($conn)); include 'creation.php'; exit(); } } } and my (messy) form <title>phpzag.com : Demo Drag and Drop File Upload using jQuery and PHP</title> <link rel="stylesheet" type="text/css" href="css/dropzone.css" /> <script type="text/javascript" src="js/dropzone.js"></script> <div class="container"> <h2>Add an Image of your amazing creation!</h2> <div class="file_upload"> <form action="?add" class="dropzone" method = "post" > <div class="dz-message needsclick"> <strong>Drag an image of your creation here to upload!</strong><br /> <span class="note needsclick">OR click to upload a file</span> </div> <span>Creation Name: <input type="text" name="creationname"> </span> <span>Number of Bricks: <input type="number" name="bricks"> </span> <span>Difficulty: <input type="range" name="difficulty" min="0" max="10"></span> </div> <input type="submit" value="Submit" > </form> </div> Quote Link to comment Share on other sites More sharing options...
mwktar Posted October 29, 2017 Author Share Posted October 29, 2017 Just realized a mistake in my understanding - the only reason difficulty is being passed is because it is defaulting on its min-max range before the image is uploaded - so it is the image being added interfering Quote Link to comment Share on other sites More sharing options...
kicken Posted October 29, 2017 Share Posted October 29, 2017 Have a look at this answer. In summary, you're not using dropzone.js correctly. It might be easier to get working if you just use a normal <input type="file"> field to start with, then after you get that working 100% try and implement drag and drop. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.