Jump to content

Another Noob Question - submitted sql being stored as array (or not at all)


mwktar

Recommended Posts

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));
}
}
}
Link to comment
Share on other sites

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 :/

Link to comment
Share on other sites

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>
Link to comment
Share on other sites

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 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.