Jump to content

Won't upload to db


martinm92

Recommended Posts

Well I wanted to avoid help for as long as I could but I have something going wrong that isn't uploading to my db however the script is working because it uploads the pictures to my server.

 

Think I just need another pair of eyes..

 

if($_SERVER['REQUEST_METHOD'] == 'POST'){
	if(($_FILES['file']['type'] == 'image/gif')
	|| ($_FILES['file']['type'] == 'image/jpeg')
	|| ($_FILES['file']['type'] == 'image/png')){
		if($_FILES['type']['error'] > 0){
			echo "Return Code: " . $_FILES['file']['error'] . "<br>";
		}else{
			$title = $_POST['title'];
			$url = $_POST['url'];
			$wwd = $_POST['wwd'];
			$otherfeat = $_POST['otherfeat'];
			$original = $_FILES['file']['name'];
			$ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);

			$newfiles = md5(time()) . "." . $ext;

			if(move_uploaded_file($_FILES['file']['tmp_name'], "./upload/".$original)){
				mysql_query("INSERT INTO `portfolio` (`title`, `webadd`, `whatwedid`, `otherfeat`, `img_org`, `img_n`) VALUES ('".$title."', '".$url."', '".$wwd."', '".$otherfeat."', '".$$original."', '".$newfiles."')");
				include ("image_resize.php");
				echo "<p>Upload successful!</p>";
			}else{
				echo "<p>Failed to upload!</p>";	
			}
		}
	}else{
		echo "<p>Invalid file type!</p>";
	}
}

 

Here is my form aswell if you want to see that.

 

    <form name="uploader" method="POST" enctype="multipart/form-data">
    <p>Title:</p>
    <p><input type="text" name="title" class="addportinput" /></p>
    <p>Website URL:</p>
    <p><input type="text" name="url" class="addportinput" /></p>
    <p>What We Did:</p>
    <p><textarea name="wwd" class="addportlongt"></textarea></p>
    <p>Other Features:</p>
    <p><textarea name="otherfeat" class="addportlongt"></textarea></p>
    <p>Screenshot:</p>
    <p><input type="file" name="file" class="addportimage" /></p>
    <p><input type="submit" class="submitButton" />
    </form>

Link to comment
Share on other sites

Most likely your query is failing. You have no error handling so you won't see the errors if they occur.

if(move_uploaded_file($_FILES['file']['tmp_name'], "./upload/".$original))
{
    $query = "INSERT INTO `portfolio`
                  (`title`, `webadd`, `whatwedid`, `otherfeat`, `img_org`, `img_n`)
              VALUES
                  ('$title', '$url', '$wwd', '$otherfeat', '$$original', '$newfiles')";
    $result = mysql_query($query);
    if(!$result)
    {
        echo "Query Failed!<br>Query: $query<br>Error: " . mysql_error();
    }

include ("image_resize.php");
    echo "<p>Upload successful!</p>";
}

Link to comment
Share on other sites

Did you notice that I created the query as a string variable first, then used that variable in the actual mysql_query() function? If the query is not producing errors but does not produce the results you want then echo the query to the page to verify if it is is built how you think it should be. In fact you should ALWAYS verify the content of dynamically created queries. Doesn't just build a query and run it and hope it works as you think. Echo the query out before even trying to run it.

 

I can see one glaring problem in your query as you built it. Look at the value you are inserting for the `img_org` field

'$$original'

 

I'm pretty sure you didn't mean to use a variable variable (i.e. the double dollar sign).

Link to comment
Share on other sites

Is spoke to soon :( I just got this error..

 

Query Failed!

Query: INSERT INTO `portfolio` (`title`, `webadd`, `whatwedid`, `otherfeat`, `img_org`, `img_n`) VALUES ('Steppin' Out', 'http://www.steppinout.me.uk/', 'PSD Design, HTML/CSS', 'We gave this website a photogallery and an admin login to allow the owner to update the photogallery.', '$stepout.jpg', 'efd897171bdd5796a3083109f35bd2db.jpg')

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Out', 'http://www.steppinout.me.uk/', 'PSD Design, HTML/CSS', 'We gave this webs' at line 4

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.