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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.