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
https://forums.phpfreaks.com/topic/236915-wont-insert-file-name-into-sql/
Share on other sites

what happens when you echo

 

$image_url

 

also

 

why is there extra space at the end of this

 

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

 

make it

 

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

what happens when you echo

 

$image_url

 

also

 

why is there extra space at the end of this

 

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

 

make it

 

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

 

This is what happens

But its still not entering the full url in the DB

FTXca.png

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

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.