Jump to content

[SOLVED] upload form not working properly


Recommended Posts

this is my code

<?php
if(isset($_POST['upload']))
{
$target = "images/";
$image = basename( $_FILES['uploadedfile']['name']);
$imagename = $_POST['imagename'];
$imagecaption = $_POST['imagecaption'];
$image_thumb = "<img src='$image' width='200px'/>";
$image_link = '<a href='.$image.' rel="lightbox" title='.$imagecaption.'>'.$imagename.'</a>'; 
$user_check = mysql_num_rows(mysql_query("SELECT * FROM `hayleyimages` WHERE image_name=1 "));
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;

//This is our size condition
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}

//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}

if($user_check >= 1)
{
echo "$imagename already exists, please rename it.";
}

//If everything is ok we try to upload it
else
{
//if($image && $imagename && $imagecaption)
//{
mysql_query("INSERT INTO `hayleyimages` (image_link,  image_name, image_caption, image_id) VALUES 	  ('$image_link','$imagename','$imagecaption', '')")
or die('Error ' . mysql_error());
	if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
	{
	echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";

	}
		else
		{
		echo "Sorry, there was a problem uploading your file.";
		}
//}
//else
//{
//echo "<br>Please make sure all fields are filled in.";
//}
}
}
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">Image Name: <input type="text" name="imagename" /><br />Image Caption: <input type="text" name="imagecaption" /></form>
<form enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Submit" name="upload" />
</form>
</body>
</html>

 

i have already connected to the database, and the file inserts properly , but it doesn't seem to insert the name and caption into the database. Can anybody see why?

Link to comment
Share on other sites

ok, i solved that part

 

now for this problem

<?php
if(isset($_POST['upload']))
{
$target = "images/";
$image =  basename( $_FILES['uploadedfile']['name']);
$imagename = $_POST['imagename'];
$imagecaption = $_POST['imagecaption'];
$image_thumb = '<img src='.$image.' width="200px"/>';
$image_link = '<a href='.$image.' rel="lightbox" title='.$imagecaption.'>'.$imagename.'</a>'; 
$user_check = mysql_num_rows(mysql_query("SELECT * FROM `hayleyimages` WHERE image_name=1 "));
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;

//This is our size condition
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}

//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}

if($user_check >= 1)
{
echo "$imagename already exists, please rename it.";
}

//If everything is ok we try to upload it
else
{
//if($image && $imagename && $imagecaption)
//{
mysql_query("INSERT INTO `hayleyimages` (image_link,  image_name, image_caption, image_id, image_thumb) VALUES 	  ('$image_link','$imagename','$imagecaption', '', '$image_thumb')")
or die('Error ' . mysql_error());
	if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
	{
	echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";

	}
		else
		{
		echo "Sorry, there was a problem uploading your file.";
		}
//}
//else
//{
//echo "<br>Please make sure all fields are filled in.";
//}
}
}
?>
<form enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">Image Name: <input type="text" name="imagename" /><br />Image Caption: <input type="text" name="imagecaption" /><br />
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Submit" name="upload" />
</form>
</body>
</html>

 

these two bits

$image_thumb = '<img src='.$image.' width="200px"/>';
$image_link = '<a href='.$image.' rel="lightbox" title='.$imagecaption.'>'.$imagename.'</a>';

are being inserted to the database as

<a href= rel="lightbox" title=test>test</a> <img src= width="200px"/>

without links , and title=test should be title="test"

does anyone know how to fix this

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.