Hi, i'm having a little problem with my php script. Here's the deal. I have 2 tables and I want to assign a post variable to a row in one table and then insert the id value of that table in another table. The script is as follows:
clients.php
<?php include "includes/config.php"; ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
if ( !isset( $_SESSION['loggedUserID'] ) ) { // user is not logged in
header( 'Location: login.php' ); // redirect to login.php
}
if (isset($_POST['add'])) {
//this is where the issue is
$agentName = mysql_real_escape_string($_POST['agentName']);
...
$sql = "INSERT INTO tblpolicydetails (..., agentID , ...)
VALUES( ..., '$agentName', ... )";
...
<script>
// some AJAX for autocomplete for textbox "agentName"
</script>
<body>
<form ...>
<p>Agent Name
<input type="text" name="agentName" ...//Some event handlers for this textbox>
...
<input type="submit" name="add" >
</form>
</body>
Now the issue is that there is a record in tblagents(not in code) with agentID = 5 say, so when i click in the "agentName" textbox an autocomplete function populates the textbox with name and surname of agent with agentID = 5 from tblagents. When i press submit i want the agentID from tblagents to be inserted into tblpolicydetails and not the name of the agent. Both tables have column name agentID.
I know there is some vital php code needed for this to work, so please help me out. Thanx in advance.