Jump to content

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