Howdy... not new to the forum, but a new poster.
I've been trying to use the code below to enter company information along with their logo. The info all loads to a new record, but the image doesn't, and actually creates a blank record below the new company in the table. I think I might know why, but being new to php I just can't figure it out. My code is:
<?php
require_once('../includes/DbConnector.php');
if ($HTTP_POST_VARS){
$connector = new DbConnector();
$insertQuery = "INSERT INTO cmscompany (company,member,street,city,state,zip,country,phone,fax,website,contact,email,thearticle) VALUES (".
"'".$HTTP_POST_VARS['company']."', ".
"'".$HTTP_POST_VARS['member']."', ".
"'".$HTTP_POST_VARS['street']."', ".
"'".$HTTP_POST_VARS['city']."', ".
"'".$HTTP_POST_VARS['state']."', ".
"'".$HTTP_POST_VARS['zip']."', ".
"'".$HTTP_POST_VARS['country']."', ".
"'".$HTTP_POST_VARS['phone']."', ".
"'".$HTTP_POST_VARS['fax']."', ".
"'".$HTTP_POST_VARS['website']."', ".
"'".$HTTP_POST_VARS['contact']."', ".
"'".$HTTP_POST_VARS['email']."', ".
"'".$HTTP_POST_VARS['thearticle']."')";
if ($action == "Load")
{
$folder = "/home/sitename/public_html/images/";
@copy("$filep" , "$folder/$filep_name");
echo "<p>File <b><i>$filep_name</i></b> loaded...</p>";
$result = mysql_connect("localhost", "user", "pw")
or die("Could not save image name Error: " . mysql_error());
@mysql_select_db("database") or die("Could not select database");
@insertQuery("INSERT into cmscompany (filep) VALUES('$filep_name')");
}
// Save the form data into the database
if ($result = $connector->query($insertQuery)){
// It worked, give confirmation
echo '<p><center><b>Company added to the database</b></center><br>';
}else{
// It hasn't worked so stop. Better error handling code would be good here!
exit('<p><center>Sorry, there was an error saving to the database</center>');
}
}
?>
...which is followed by the form:
<form enctype="multipart/form-data" name="Companies" method="POST" action="newcompany.php">
<div class="row"><span class="label">Company:</span><span class="formw">
<input name="company" type="text" size="35" id="company" />
</span></div>
<div class="row"><span class="label">Member:</span><span class="formw">
<input name="member" type="text" size="35" id="member" />
</span></div>
<div class="row"><span class="label">Street:</span><span class="formw">
<input name="street" type="text" size="35" id="street" />
</span></div>
<div class="row"><span class="label">City:</span><span class="formw">
<input name="city" type="text" size="35" id="city" />
</span></div>
<div class="row"><span class="label">State:</span><span class="formw">
<input name="state" type="text" size="35" id="state" />
</span></div>
<div class="row"><span class="label">Zip:</span><span class="formw">
<input name="zip" type="text" size="35" id="zip" />
</span></div>
<div class="row"><span class="label">Country:</span><span class="formw">
<input name="country" type="text" size="35" id="country" />
</span></div>
<div class="row"><span class="label">Phone:</span><span class="formw">
<input name="phone" type="text" size="35" id="phone" />
</span></div>
<div class="row"><span class="label">Fax:</span><span class="formw">
<input name="fax" type="text" size="35" id="fax" />
</span></div>
<div class="row"><span class="label">Website:</span><span class="formw">
<input name="website" type="text" size="35" id="website" />
</span></div>
<div class="row"><span class="label">Contact:</span><span class="formw">
<input name="contact" type="text" size="35" id="contact" />
</span></div>
<div class="row"><span class="label">Email:</span><span class="formw">
<input name="email" type="text" size="35" id="email" />
</span></div>
<div class="row"><span class="label">Description:</span><span class="formw">
<textarea name="thearticle" cols="30" rows="6" id="thearticle"></textarea>
</span></div>
<div class="row"><span class="label">Logo:</span><span class="formw">
<input type="file" name="filep" size="25" id="filep">
</span></div>
<div class="row"><span class="formw">
<input type="submit" name="action" value="Load" />
<input type="reset" value="Reset Form" />
</span></div>
<div class="spacer"> </div>
</form>
Is it wrong to try and upload the image at the same time as the text fields? Can't this be done?
SO much thanks in advance folks... Have a great day!
Superfrappe