Jump to content

Wont insert file name into SQL


rog1121

Recommended Posts

I've Basically got this script and everything works. Except for the part that it doesen't insert "$_FILES['file']['name']" into the image_url.

 

Any Ideas guys?

 

5ojke.png

 

<? 
include "includes/config.php";

if (isset($_POST['add'])) {
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    if (file_exists("images/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
  echo $_FILES['file']['name'];
      }
    else
      {

      move_uploaded_file($_FILES["file"]["tmp_name"],
      "images/" . $_FILES["file"]["name"]);
      }
    }
  }
else
  {
  echo "Sorry, but only PNG, JPG, and GIF files are allowed.";
  }
  mysql_connect ($mysql_host, $mysql_user, $mysql_pass);
  mysql_select_db ($mysql_db);

$image_url = "http://localhost/admin/images/". $_FILES['file']['name'] ."";

$sql = "INSERT INTO test (title, link, description, image_url)
VALUES
('$_POST[title]', '$_POST[link]', '$_POST[description]', '$image_url')";

if (!mysql_query($sql))
  {
  die('Error: ' . mysql_error());
  }
header( 'Location: portfolio.php' );

mysql_close();
}

?> 

 

<form enctype="multipart/form-data" method="post">
			<p>
				<strong>TITLE</strong><br/>
				<input type="text" name="title" class="box"/>
			</p>				<p>
				<strong>LINK</strong><br/>
				<input type="text" name="link" class="box"/>
			</p>
			<p>
				<strong>IMAGE</strong><br/>
				<input type="file" class="box" name="file"/>
			</p>
			<p>
				<strong>DESCRIPTION</strong><br/>
				<input type="textarea" name="description" class="box"/>
			</p>
			<p>
				<input name="add" type="submit" id="submit" tabindex="5" class="com_btn" value="ADD WORK"/>
			</p>
		</form>

Link to comment
Share on other sites

At the top of the script, put the following code and post the output it generates after the form has been submitted.

 

echo '$_FILES array contains:<br>';
echo '<pre>';
print_r($_FILES);
echo '</pre>';

 

EDIT: Nevermind, you must have been marking it solved as I was posting . . .

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.