Jump to content

[SOLVED] problem with passing variable in hidden form field to database


joshgarrod

Recommended Posts

I have an image uploader and submitting form, the form uploads the image and stores it in a folder called "uploads", then I need to find the name of the image and store it in the database field "image" so that it knows where to source the image from when I process the data. All it does at the mo is puts "uploads/" into the databse. Can any body help please?

 

PHP:

<?php
  
  $idir = "uploads/";   // Path To Images Directory


if (isset ($_FILES['fupload'])){

//upload the image to tmp directory
$url = $_FILES['fupload']['name'];   // Set $url To Equal The Filename For Later Use 
	if ($_FILES['fupload']['type'] == "image/jpg" || $_FILES['fupload']['type'] == "image/jpeg" || $_FILES['fupload']['type'] == "image/pjpeg") { 
		$file_ext = strrchr($_FILES['fupload']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php 
		$copy = copy($_FILES['fupload']['tmp_name'], "$idir" . $_FILES['fupload']['name']);   // Move Image From Temporary Location To Permanent Location 
			if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location 
			print '' .$url . ' Image uploaded successfully.<br />';   // Was Able To Successfully Upload Image 
			}
			}
			}
  
error_reporting (E_ALL ^ E_NOTICE);
    $usr = "usr";
    $pwd = "pass";
    $db = "fb";
    $host = "host";


    # connect to database
    $cid = mysql_connect($host,$usr,$pwd);
    if (!$cid) { echo("ERROR: " . mysql_error() . "\n");    }

    if ($_POST['submit']) {

	$title = mysql_real_escape_string($_POST['title']);
	$descr = mysql_real_escape_string($_POST['descr']);
	$partno = mysql_real_escape_string($_POST['partno']);
	$price = mysql_real_escape_string($_POST['price']);
	$avail = mysql_real_escape_string($_POST['avail']);
	$image = mysql_real_escape_string($_POST['image']);

        $SQL = "INSERT INTO spares";
        $SQL .= " (title, descr, partno, price, avail, image) VALUES ";
	$SQL .= " ('$title','$descr','$partno','$price', '$avail', '$image') ";

	      
        $result = mysql_db_query($db,$SQL,$cid);

        if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n");    }

        echo ("<P><B>Congratulations... you have successfully added a new part to the stock list - $image_name</B></P>\n");

    }

?>

 

HTML:

<input name="image" type="hidden" value="uploads/<?php echo $url; ?>" />

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.