I am trying to create a form where a user can submit an image with a description attached to it. It is pulling data from two different tables in mysql. The page loads when I remove the php code. The code is from two different pages i have now. Both of which work individually. the first is a form upload and the second is a picture upload page. This will be used to combine the two pages into a single upload.
this is the page code. Please Help!!!!
<?php
session_start();
if (!isset($_SESSION['id'])) {
echo 'Please <a href="login.php">log in</a> to access your account';
exit();
include_once "../../../Pintrading/members/memberSystemBasic/connect_to_mysql.php";
$username = $_SESSION['username'];
$category = ereg_replace("[^A-Z a-z0-9]", "", $_POST['category']); // filter everything but spaces, numbers, and letters
$pinname = ereg_replace("[^A-Z a-z0-9]", "", $_POST['pinname']); // filter everything but spaces, numbers, and letters
$year = ereg_replace("[0-9]", "", $_POST['year']); // filter everything but spaces, numbers, and letters
$condition = ereg_replace("[^A-Z a-z0-9]", "", $_POST['condition']); // filter everything but lowercase letters
if((!$category) || (!$pinname) || (!$year) || (!$status) || (!$condition)){
$errorMsg = "You did not submit the following required information!<br /><br />";
if(!$category){
$errorMsg .= "--- Category";
}else if(!$pinname){
$errorMsg .= "--- Pin Name";
} else if(!$year){
$errorMsg .= "--- Year";
} else if(!$status){
$errorMsg .= "--- Status";
}else if(!$condition){
$errorMsg .= "--- Condition";
}
} else {
$sql = mysql_query("INSERT INTO pin (username, category, pinname, year, condition)
VALUES('$username','$category','$pinname','$year', '$condition', now())") or die (mysql_error());
}
if ($_FILES['uploadedfile']['tmp_name'] != "") {
// Run error handling on the file
// Set Max file size limit to somewhere around 120kb
$maxfilesize = 120000;
// Check file size, if too large exit and tell them why
if($_FILES['uploadedfile']['size'] > $maxfilesize ) {
echo "<br /><br />Your image was too large. Must be 100kb or less, please<br /><br />
<a href=\"submit_pin.php\">click here</a> to try again";
unlink($_FILES['uploadedfile']['tmp_name']);
exit();
// Check file extension to see if it is .jpg or .gif, if not exit and tell them why
} else if (!preg_match("/\.(gif|jpg)$/i", $_FILES['uploadedfile']['name'] ) ) {
echo "<br /><br />Your image was not .gif or .jpg and it must be one of those two formats, please<br />
<a href=\"submit_pin.php\">click here</a> to try again";
unlink($_FILES['uploadedfile']['tmp_name']);
exit();
// If no errors on the file process it and upload to server
} else {
// Rename the pic
$newname = "<?php echo "$pinname"; ?>.jpg";
// Set the direntory for where to upload it, use the member id to hit their folder
// Upload the file
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], "memberFiles/$id/".$newname)) {
echo "Success, the image has been uploaded and will display to visitors!<br /><br />
<a href=\"member_account.php\">Click here</a> to return to your profile edit area";
exit();
} else {
echo "There was an error uploading the file, please try again. If it continually fails, contact us by email. <br /><br />
<a href=\"member_account.php\">Click here</a> to return to your profile edit area";
exit();
}
} // close else after file error checks
}
}
// close if post the form
?>
<script type="text/javascript">
<!-- Form Validation -->
function validate_form ( ) {
valid = true;
if ( document.form.uploadedfile.value == "" ) {
alert ( "Please browse for a file on your PC and place it" );
valid = false;
}
return valid;
}
<!-- Form Validation -->
</script>
<body>
<table width="600" align="center" cellpadding="4">
<tr>
<td width="7%">List Pins to Trade </td>
</tr>
</table>
<table width="600" align="center" cellpadding="5">
<form action="submit_pin.php" method="post" enctype="multipart/form-data" name="form" id="form" onSubmit="return validate_form ( );">
<tr>
<td colspan="2"><font color="#FF0000"><?php echo "$errorMsg"; ?></font></td>
</tr>
<tr>
<td width="163"><div align="right">Pin Name:</div></td>
<td width="409"><input name="pinname" type="text" value="<?php echo "$pinname"; ?>" /></td>
</tr>
<tr>
<td><div align="right">Category:</div></td>
<td><select name="category">
<option value="<?php echo "$category"; ?>"><?php echo "$category"; ?></option>
<option value="a">Attraction</option>
<option value="b">Character</option>
<option value="c">Event</option>
<option value="d">Film</option>
<option value="e">Holiday</option>
<option value="f">Miscellaneous</option>
<option value="g">Park</option>
<option value="h">Princesses</option>
<option value="i">Resort</option>
</select></td>
</tr>
<tr>
<td><div align="right">Year: </div></td>
<td><input name="year" type="text" value="<?php echo "$year"; ?>" /></td>
</tr>
<tr>
<td><div align="right">Condition: </div></td>
<td><select name="condition">
<option value="<?php echo "$condition"; ?>"><?php echo "$condition"; ?></option>
<option value="a">New</option>
<option value="b">Used Like New</option>
<option value="c">Used Slightly Worn</option>
<option value="d">Used Acceptable</option>
<option value="e">Used Damaged</option>
</select></td>
</tr>
<tr>
<td colspan="2"><img src="memberFiles/<?php echo "$id"; ?>/<?php echo "$pinname"; ?>.jpg" alt="Ad" width="150" /></td>
</tr>
<tr>
<td colspan="2"><input name="uploadedfile" type="file" /></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><input type="submit" name="Submit" value="Submit Form" /></td>
</tr>
</form>
</table>
</body>