I've been working on this app, and right now I'm developing a form that will insert info into a database (mysql), while at the same time uploading several images into my images folder and also inserting the file name of those images into the database as well. Everything is uploading fine into the folder and my other text entries are being added to the db, except the image file names. Those columns are blank. Heres my code:
<?php
include ('connect.php');
$dbconnect = mysql_select_db('aircraftsales');
$actypelist = mysql_query('SELECT ID, type FROM ac_type');
?>
<form name="addaircraft" method="post" action="<?=$_SERVER['PHP_SELF']?>"
enctype="multipart/form-data">
Add aircract to which aircraft type?:
<select name="typeID">
<option value="">Aircraft Type</option>
<option value="">- - - - - - - -</option>
<?php
while($actype = mysql_fetch_array($actypelist)) {
$typeID = $actype['ID'];
$type = $actype['type'];
echo('<option value="' . $typeID . '">' . $type . "</option>\n" );
}
?>
</select>
<br><br>
Aircraft Name: <input type="text" size="50" maxlength="100" name="ac_name">
<br>
Serial Number: <input type="text" size="50" maxlength="100" name="serial_num"><BR>
Registration Number: <input type="text" size="50" maxlength="100" name="registration_num"><BR>
Engines<BR>
Left:<input type="text" size="50" maxlength="100" name="L_engine"><BR>
Right:<input type="text" size="50" maxlength="100" name="R_engine"><BR>
Propellers<br>
Left:<input type="text" size="50" maxlength="100" name="L_propeller"><BR>
Right:<input type="text" size="50" maxlength="100" name="R_propeller"><BR>
Center:<input type="text" size="50" maxlength="100" name="C_propeller"><BR>
Interior:
<br>
<textarea cols="80" rows="10" name="interior"></textarea>
<script language="JavaScript1.2" defer>
editor_generate('topic_text');
</script>
<br><br>
Exterior<br>
<textarea cols="80" rows="10" name="exterior"></textarea><br>
Optional Equipment:<br>
<textarea cols="80" rows="10" name="optional_equip"></textarea><br>
Avionics:<br>
<textarea cols="80" rows="10" name="avionics"></textarea>
<br>
Exterior Image: <input type="file" name="img_exterior"> <br>
Cockpit Image: <input type="file" name="img_cockpit"> <br>
Interior Image: <input type="file" name="img_interior"> <br>
<input type="submit" value="submit" name="submit">
</form>
Code: Select all
if(isset($_POST['submit'])) {
$typeID = (int) $_POST['actype_ID'];
$ac_name = addslashes($_POST['ac_name']);
$serial_num = addslashes($_POST['serial_num']);
$registration_num = addslashes($_POST['registration_num']);
$L_engine = addslashes($_POST['L_engine']);
$R_engine = addslashes($_POST['R_engine']);
$L_propeller = addslashes($_POST['L_propeller']);
$R_propeller = addslashes($_POST['R_propeller']);
$C_propeller = addslashes($_POST['registration_num']);
$interior = addslashes($_POST['interior']);
$exterior = addslashes($_POST['exterior']);
$optional_equip = addslashes($_POST['optional_equip']);
$avionics = addslashes($_POST['avionics']);
//confused somewhere here.
if ($_FILES['img_exterior']['type'] == "image/gif" or $_FILES['img_exterior']['type'] == "image/pjpeg"){
move_uploaded_file($_FILES['img_exterior']['tmp_name'], "images/".$_FILES['img_exterior']['name'])
or die ("Could not copy"); }
else {
echo "Could Not Copy, Wrong Filetype (".$_FILES['img_exterior']['name'].")";
}
//}
//interior upload
if ($_FILES['img_interior']['type'] == "image/gif" or $_FILES['img_interior']['type'] == "image/pjpeg"){
move_uploaded_file($_FILES['img_interior']['tmp_name'], "images/".$_FILES['img_interior']['name'])
or die ("Could not copy"); }
else {
echo "Could Not Copy, Wrong Filetype (".$_FILES['img_interior']['name'].")";
}
//}
if ($_FILES['img_cockpit']['type'] == "image/gif" or $_FILES['img_cockpit']['type'] == "image/pjpeg"){
move_uploaded_file($_FILES['img_cockpit']['tmp_name'], "images/".$_FILES['img_cockpit']['name'])
or die ("Could not copy"); }
else {
echo "Could Not Copy, Wrong Filetype (".$_FILES['img_cockpit']['name'].")";
}
//}
echo($ac_name);
$sql = 'INSERT INTO ac_description SET
actype_ID = ''' . $typeID . ''',
ac_name = ''' . $ac_name . ''',
serial_num = ''' . $serial_num . ''',
registration_num = ''' . $registration_num . ''',
L_engine = ''' . $L_engine . ''',
R_engine = ''' . $R_engine . ''',
L_propeller = ''' . $L_propeller . ''',
R_propeller = ''' . $R_propeller . ''',
C_propeller = ''' . $C_propeller . ''',
interior = ''' . $interior . ''',
exterior = ''' . $exterior . ''',
optional_equip = ''' . $optional_equip . ''',
avionics = ''' . $avionics . ''',
img_exterior = ''' . $_REQUEST['img_exterior']['name'] . ''',
img_interior = ''' . $_REQUEST['img_interior']['name'] . ''',
img_cockpit = ''' . $_REQUEST['img_cockpit']['name'] . '''';
if (@mysql_query($sql)) {
echo('The new aircraft has been added ');
} else {
echo('could not add new aircraft:' . mysql_error());
}
}why won't the image names enter into the database??