Forum Moderators: coopster

Message Too Old, No Replies

Trouble passing a variable

         

BadGoat

6:05 pm on Oct 14, 2009 (gmt 0)

10+ Year Member



Hello!

I am having trouble passing a variable which is pulled from a database entry:

<tr>
<td>Name:</td>
<td><select name="NameID"><option value="notset">- Select Name -</option> ';

//--- CREATE SELECT ---
$sql = "SELECT DISTINCT * FROM ArchType ORDER BY Name";
$squig = mysql_query($sql) or die($sql . '<br />' . mysql_error());
while ($row = mysql_fetch_array($squig)) {
echo '<option value="' . $row['TypeID'] . '">' . $row['Name'] . '</option>
';}; echo '</select></td>
</tr>

When I select the Name variable, I insert it into a MySQL table:


$sqlquery = "INSERT INTO aka (NameID, akaName) VALUES('". $_POST['NameID'] ."', '". $_POST['akaName'] ."')";
$queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query 1!");
$sqlquery = "SELECT * from aka";

So far so good. Variables pass and get inserted. But I want to also insert the ID (not the NameID) that comes from ArchType.. so if the name 'Bob' gets inserted into table 'aka', I want to also insert the ID from the table where all the names are stored. I know how to do the MySQL part, but I am at a loss of how to grab the ID from one table and insert it as a variable in a second.

Is this even possible?
Thank you

nanat

1:07 am on Oct 15, 2009 (gmt 0)

10+ Year Member



what do you mean? your primary key is TypeID? or different ID?
Probably <option value="' . $row['TypeID'] . '"> are the same with <select name="NameID">

if the have primaryID name ID..


<tr>
<td>
echo '
<input type="hidden" size="6" name="MyID" value="'.ID.'">';
</td>
</tr>

onsubmit:

$sqlquery = "INSERT INTO aka (ID,NameID, akaName) VALUES(, '". $_POST['MyID'] ."','". $_POST['NameID'] ."', '". $_POST['akaName'] ."')";