Jump to content

Upload Image and Add path to MySql Database


bigshwa05

Recommended Posts

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

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.