passing hidden values in form

I’m trying to create a tracking system. it has a mysql database with two tables clients and jobs. I have a php form to add new clients. each client has an auto incrementing id when created.

i want to create an add job form that populates all clients from the client database into a dropdown (which i have done) but i also want it to pass along that unique client id so that i can use that number to join the tables later on.

this is what i have for the add job form so far
[php]<?php
$result = mysql_query(“SELECT * FROM clients ORDER BY lName”);
echo"";
echo"";
echo"";
while($row=mysql_fetch_assoc($result))
{
echo “”.$row[‘lName’]." “.$row[‘fName’].”";
}
echo"";
echo"



“;
echo”";
?>[/php]

use a hidden input. (replace id with whatever your id is)

It doesn’t seem to pass the id value over to the process page.

addjob.php[php]
<?php
$result = mysql_query(“SELECT * FROM clients ORDER BY lName”);
echo"";
echo"";
echo"";
while($row=mysql_fetch_assoc($result))
{
echo “”.$row[‘lName’]." “.$row[‘fName’].”";
echo"<input type=‘hidden’ name=‘uid’ value=’".$row[‘id’]."’ />";
}

	echo"<p>
     <input type='submit' name='submit' class='submit' id='submit' value='Add Job' tabindex='90' />
     </p>";
	 echo"</form>";
	
?>

[/php]

addJobProcess.php
[php] if(isset ($_POST[‘submit’]))
{
include(“includes/connect.php”);

 $name = $_POST['myselect'];
 $uid = $_POST['uid'];

}

	 echo $name;
	 echo"</ br>";
	 echo $uid;

?>[/php]

I don’t think when the name is selected from the drop down that the id is being populated in the hidden field

it says undefined variable id on line 7

It doesn’t go inside the loop. on the addjobprocess page, you don’t need that if statement

it’s still not working.

say the dropdown has two names john smith and frank wood. johns id from the database is 3 and franks is 1.

when john is selected from drop down I want that hidden field to populate his id from the database which is 3. that part seems to not be working. do i need some kind of onclick js or something?

no, just put it as the value for the option, instead of the last name. Either that, or you’ll have to either use ajax or get the id on the addjobprocess page.

Thank you for all your help. I think I’m going to have to get the id from the process page. How would i go about that? any pointers? Thanks again

addJobProcess.php

Change the method from POST to GET.
[php]
include(“includes/connect.php”);
$name = $_GET[‘myselect’];

$find_id = mysql_query(“SELECT id FROM users WHERE name = ‘$name’”) or die(mysql_error());
$r = mysql_fetch_assoc($find_id);

if(mysql_num_rows($find_id) != 0) {
echo $name."
";
echo $r[‘id’];
} else {
echo “No record could be found for $name”;
}
[/php]
Something like that.

Sponsor our Newsletter | Privacy Policy | Terms of Service