[SOLVED] ID from dropdown menu not being inserted into da...

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] ID from dropdown menu not being inserted into da...

Post by jive »

Ok, so everything seems like it was being inserted into the database upon submit, but looking more closely, I realized that an ID from a from my dropdown menu was not being submitted into the database to join my two tables. Heres my code:


Code: Select all

include ('connect.php');

$dbconnect = mysql_select_db('aircraftsales');
<form name="addaircraft" method="post" action="<?=$_SERVER['PHP_SELF']?>"

enctype="multipart/form-data">

Add aircraft to which aircraft type?:

<select name="typeID">

<option value="">Aircraft Type</option>

<option value="">- - - - - - - -</option>

Code: Select all

//here is my dropdown menu

 

$actypelist = mysql_query('SELECT ID, type FROM ac_type');

 

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']);

 

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($actype_ID);

$sql = 'INSERT INTO ac_description SET

        actype_ID = ''' . $typeID . ''', //not being entered in the database??

        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());

}

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

Post by infolock »

your problem is in this line :

Code: Select all

<?php

if(isset($_POST['submit']))
{
	$typeID = (int) $_POST['actype_ID']; 
//...........

?>
you aren't assigning actype_ID to any of the form values above, so therefore there is nothing to return.

from what i can tell, instead of actype_ID, you are using ac_name.

otherwise, you may need to figure out what value actype_ID is suposed to stand for in your form
jive
Forum Newbie
Posts: 20
Joined: Thu May 23, 2002 1:34 pm
Contact:

Post by jive »

Its supposed to grab it from this part of the form. The "typeID" is where I'm trying to pull it from. I want the typeID value to be passed...

form name="addaircraft" method="post" action="<?=$_SERVER['PHP_SELF']?>"

enctype="multipart/form-data">

Add aircraft to which aircraft type?:

<select name="typeID">

<option value="">Aircraft Type</option>

<option value="">- - - - - - - -</option>

Code: Select all

//here is my dropdown menu

 

$actypelist = mysql_query('SELECT ID, type FROM ac_type');

 

while($actype = mysql_fetch_array($actypelist)) {

$typeID = $actype['ID'];

$type = $actype['type'];

echo('<option value="' . $typeID . '">' . $type . "</option>\n" );

}
</select>
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

heh :oops: i missed that one :P

but anyways, have you tried taking out the (int) in the call $typeID = (int) $_POST['actype_ID']; to where it just reads $typeID = $_POST['actype_ID']; ?


might try that at least. i'm still just not seeing anything wrong.
ghost007
Forum Commoner
Posts: 49
Joined: Sat Nov 22, 2003 10:10 am

Post by ghost007 »

I think infolock was right.

just try to change this in your code and see if it works:
YOU:
$typeID = (int) $_POST['actype_ID'];

CHANGE TO:
$typeID = (int) $_POST['typeID'];

just let me know if this worked out but I think it will

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

Post by jive »

that was it. That worked. Thanks!! :D
Post Reply