Forum Moderators: coopster
I have a contact table, which naturally lists all of our clients. When they make a purchase, we update the order table and as part of that, we need to tie that order back to their client entry. When I try to pick up and enter the "clientID" in the order table, all I get is a zero(0). Everything else populates correctly. Below are the two scripts involved. The first is the display where the ClientID comes from, and yes, it gets passed over to the second, but does not make it to the SQL statement.
Any advice would be appreciated...Sorry for the messy code...
----------------------------------------------------
Client Search...
// Define the query.
$query = ("SELECT * FROM `clients` WHERE `LastName`='{$_POST['lname']}'");
if ($r = mysql_query ($query)) { // Run the query.
// Retrieve and print every record
while ($row = mysql_fetch_array ($r)) {
print "<p><strong>{$row['LastName']}, {$row['FirstName']} - {$row['Address1']} - {$row['City']}, {$row['State']}, {$row['Zip']}</strong><br />
<a href=\"edit_entry_test.php?id=
{$row['clientID']}\">Edit</a> ¦ 
<a href=\"order_entry.php?id=
{$row['clientID']}\">Enter Order</a> ¦ 
<a href=\"view_client.php?id=
{$row['clientID']}\">View</a> ¦ 
<a href=\"client_entry.php\">Add Client</a> ¦ 
</p><hr />\n";
}
} else { // Query didn't run.
die ('<p>Could not retrieve the data because:
<b>' . mysql_error() . "</b>.
The query was $query.</p>");
} // End of query IF.
----------------------------------------------------
Order Entry...
if (isset ($_POST['submit'])) { // Handle the form.
// Connect and select.
if ($dbc = @mysql_connect ('localhost', 'user', 'password')) {
if (!@mysql_select_db ('db')) {
die ('<p>Could not select the database because: <b>' . mysql_error() . '</b></p>');
}
} else {
die ('<p>Could not connect to MySQL because: <b>' . mysql_error() . '</b></p>');
}
// Define the query.
$query = "INSERT INTO cruise (cruiseID, clientID, CruiseDate, ReturnDate, Ship, GrpBookingID, BookingID, FinalPayDate, TotalDepAmt, FullDepDate, GroupName, Itinerary, Length, EmbarkPort, DisembarkPort, Port1, Port2, Port3, Port4, Port5, Port6, Port7, Port8, Port9, Port10, CruiseCom, RoomingCom, Notes)
VALUES ('', '{$_POST['clientID']}', '{$_POST['cruisedate']}', '{$_POST['retdate']}', '{$_POST['ship']}', '{$_POST['grpbookingid']}',
'{$_POST['bookingid']}', '{$_POST['finalpaydate']}', '{$_POST['totaldepamt']}', '{$_POST['fulldepdate']}', '{$_POST['groupname']}',
'{$_POST['intinerary']}', '{$_POST['length']}',
'{$_POST['embark']}', '{$_POST['disembark']}', '{$_POST['port1']}', '{$_POST['port2']}', '{$_POST['port3']}',
'{$_POST['port4']}', '{$_POST['port5']}', '{$_POST['port6']}',
'{$_POST['port7']}', '{$_POST['port8']}', '{$_POST['port9']}', '{$_POST['port10']}', '{$_POST['cruisecom']}', '{$_POST['roomingcom']}', '{$_POST['notes']}')";
// Execute the query.
if (@mysql_query ($query)) {
print '<p>The client entry has been added.<a href="/documents/client_search.php">Client Search</a> -- <a href="www.example.com">Home Page</a></p>';
} else {
print "<p>Could not add the entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>";
}
mysql_close();
}
// Display the form.
?>
Please enter the Client information: <br />
<form name="crentry" id="crentry" method="post" action="order_entry.php">
<table>
<tr>
<td colspan="2"><label for="cruisedate">Cruise Date:</label></td>
<td colspan="2"> <name="cruisedate" id="cruisedate" tabindex="1"/><?php echo make_date_menus(2004, 4)?></td>
</tr>
<-- removed a bunch of fields -->
<tr>
<td colspan="2"><label for="notes">Notes:</label></td>
<td colspan="2"> <textarea name="notes" id="notes" rows="3" cols="30" tabindex="26"></textarea></td>
</tr>
</table>
<input type="submit" name="submit" value="Enter Cruise" />
[edited by: jatar_k at 9:17 pm (utc) on June 5, 2004]
[edit reason] reduced code [/edit]
Although I'm not sure how you have your forms/scripts separated, at first glance, it appears you are trying to use the
clientIDfield from the $_POST [php.net] superglobal, but it doesn't exist there. You are passing the
clientIDvia the $_GET superglobal in your
a hrefattribute.