Jump to content

[SOLVED] Trying to upload an image and text while making an entry to MyQSL Table


djr587

Recommended Posts

So I am tryin gto upload an image to my database -- the image uploads, the files goes to the correct directory - things are working on that end.

 

BUT the same code is supposed to update the table on the database with an id, title, caption, imgname, imgdir .

 

Its putting the ID, and img name & dir .. but no title or caption.

 

heres the instert code:

<?php

//select a database to work with

$selected = mysql_select_db("shape4_shape",$dbhandle)

  or die("Could not select examples");

if ($_POST['submit']) {

echo "Name:".$_FILES['img']['name']."<br>"; 

echo "Type:".$_FILES['img']['type']."<br>";

echo "Size:".($_FILES['img']['size'] / 1024)." "."KB"."<br>";

echo "Temp Name:".$_FILES['img']['tmp_name']."<br>";

}

if ($_POST['submit']) {

if ($_FILES['img']['tmp_name']) {

$imgname=uniqid("FD").".jpg";

move_uploaded_file($_FILES['img']['tmp_name'],"featureimage/$imgname");

$realname=$_FILES['img']['name'];

mysql_query("INSERT INTO featuremini (`id` ,`title` ,`cap` ,`imagename` ,`imagedir`) VALUES (NULL , '$_GET[title]', '$_GET[cap]', '$realname', 'featureimage/$imgname')");

}

}

?>

 

The form is set witth the proper enc type and data is properly labeled .. but it just wont insert values for the two text elements.

 

DO i have to build this procedure in two steps  ? one form up load the image, and one form to update that tables text for those values by pulling the most recent entry and adding to it ?

Correction to Michdd:

 

mysql_query("INSERT INTO featuremini (`id` ,`title` ,`cap` ,`imagename` ,`imagedir`) VALUES ('', '{$_GET['title']}', '{$_GET['cap']}', '$realname', 'featureimage/$imgname')");

Still not imputing the text data .. argh !!!

 

Heres the code minus my connect ....

 

<?php
//select a database to work with
$selected = mysql_select_db("shape4_shape",$dbhandle)
  or die("Could not select examples");
if ($_POST['submit']) {
echo "Name:".$_FILES['img']['name']."<br>";  
echo "Type:".$_FILES['img']['type']."<br>"; 
echo "Size:".($_FILES['img']['size'] / 1024)." "."KB"."<br>"; 
echo "Temp Name:".$_FILES['img']['tmp_name']."<br>"; 
}
if ($_POST['submit']) {
if ($_FILES['img']['tmp_name']) {
$imgname=uniqid("FD").".jpg";
move_uploaded_file($_FILES['img']['tmp_name'],"featureimage/$imgname");
$realname=$_FILES['img']['name'];
mysql_query("INSERT INTO featuremini (`id` ,`title` ,`cap` ,`imagename` ,`imagedir`) VALUES ('', '{$_GET['title']}', '{$_GET['cap']}', '$realname', 'featureimage/$imgname')");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="" method="post" enctype="multipart/form-data">
  <input name="title" type="text" id="title" size="25" />
    <input name="cap" type="text" id="cap" size="25" />
<input name="img" type="file" /> <br /><br />
<input name="submit" type="submit" value="submit" />
</form>
</body>
</html>

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.