[SOLVED] file names not being entered in database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jive
Forum Newbie
Posts: 20
Joined: Thu May 23, 2002 1:34 pm
Contact:

[SOLVED] file names not being entered in database

Post by jive »

Hello again folks,



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??
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

cleaned up your code and try the FILE instead of REQUEST:

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 = '".$_FILES['img_exterior']['name']."', 
        img_interior = '".$_FILES['img_interior']['name']."', 
		img_cockpit = '". $_FILES['img_cockpit']['name']."'"; 

if (@mysql_query($sql)) 
{ 
    echo('The new aircraft has been added '); 
} 
else 
{ 
    echo('could not add new aircraft:' . mysql_error()); 
} 

}

if it doesn't work, let me know. but if you notice how i'm exiting out of that sql statement to add variables, try to follow that. it's a lot more neat, and more productive (imo) :)
jive
Forum Newbie
Posts: 20
Joined: Thu May 23, 2002 1:34 pm
Contact:

Post by jive »

thanks! :D
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

np man, need anything else you know where to find us
jive
Forum Newbie
Posts: 20
Joined: Thu May 23, 2002 1:34 pm
Contact:

Post by jive »

Here another prob I ran into. :(

viewtopic.php?t=14867
Post Reply