Jump to content


Photo

Upload Image and Add path to MySql Database


  • Please log in to reply
1 reply to this topic

#1 bigshwa05

bigshwa05
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 05 June 2006 - 03:12 AM

I am trying to create a form to uplaod an image along with some form data. I can get the form to write the text values into the database however the image does not seem to upload. I m not sure what to try next!

<?

//connect

mysql_connect("myHost","userName","password");

//select which database you want to edit
mysql_select_db("dataBase");
?>
<?
//initilize PHP

if($_POST['submit']) //If submit is hit
{
//convert all the posts to variables:
$bizname = $_POST['bizname'];
$bizwebsite = $_POST['bizwebsite'];
$bizcategory = $_POST['bizcategory'];
$bizdescription = $_POST['bizdescription'];
$imagename = $_FILES['image']['name'];

copy ($_FILES['image']['tmp_name'], "../images/".$_FILES['image']['name']) or die ('Could not upload');

$result=MYSQL_QUERY("INSERT INTO bizdir (

id,
bizname,
bizwebsite,
bizcategory,
bizdescription
imagename)".

"VALUES ('NULL', '$bizname', '$bizwebsite', '$bizcategory', '$bizdescription','$imagename')");
echo '<p>test</p>';
}

else

{

// close php so we can put in our code

?>

<form method="post" action="addbiz.php">
<TABLE>
<TR>
<TD>Business Name:</TD>
<TD><INPUT TYPE='TEXT' NAME='bizname' VALUE='Random Name' size=60></TD>
</TR>
<TR>
<TD>Website:</TD>
<TD><INPUT TYPE='TEXT' NAME='bizwebsite' VALUE='' size=60></TD>
</TR><br>
<TR>
<TD>CATEGORY:</TD>
<TD><INPUT TYPE='TEXT' NAME='bizcategory' VALUE='' size=60></TD>
</TR>
<TR>
<TD>Description:</TD>
<TD>
<!-- You can use PHP functions to automatically get the value of time -->
<TEXTAREA NAME='bizdescription' VALUE='description' rows="10" cols="30"></TEXTAREA>
</TD>
</TR>
<TR>
<TD>Image:</TD>
<TD>
<!-- You can use PHP functions to automatically get the value of time -->
<input type="file" name="image">
</TD>
</TR>
<TR>
<TD></TD><br>
<TD><INPUT TYPE="submit" name="submit" value="submit"></TD>
</TR>
</TABLE>
</form>
<?
} //close the else statement
?>

#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 06 June 2006 - 03:45 AM

As a start try changing this

<form method="post" action="addbiz.php">

to this

<form enctype="multipart/form-data" action="addbiz.php" method="post">

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users