clickernon Posted March 24, 2010 Share Posted March 24, 2010 I cannot figure out how to do the following. Please bear with me because it is complicated, so it takes a lot of information to explain it. This is a picture of what I am trying to do: (user submitted a search on a previous page and received the following on the search.php page) Your search “Florida” returned the following results: Date From Date To ID (hidden column) 4/12/2010 5/6/2010 12 6/3/2010 6/20/2010 22 1/10/2011 3/6/2011 87 Comment (form field completed by the user with the following words): Congratulations and good luck! Submit I want the information submitted from the “Comment” form field (comments) to be posted to the feedback mysql table with each hidden ID value. So in this case the feedback mysql table would receive the following values: VID Comments 12 Congratulations and good luck! 22 Congratulations and good luck! 87 Congratulations and good luck! There are 2 mysql tables with the following fields: member – ID, Location, DateFrom, DateTo feedback – ID, VID, Comments The ID field in Member and the VID field in Feedback are connected so that the comments in the feedback table are related to a specific member in the member table. I can get the comments into the feedback table, but I cannot get the VID into it (i.e., the ID from the member table). A user searches the member mysql table for members located in a certain city (Location). After submission, the user is taken to the searchresults.php page which returns the results and provides a form field (comments) for the user to provide feedback to the members in that location: searchresults.php PHP Code: <?php $con = mysql_connect("localhost","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("", $con); $term = $_POST['location']; $result = mysql_query("select * from member where Location like '%$term%'"); echo "<h3>Your search "" . $term . "" returned the following results:</h3>"; echo "<table border='1'> <tr> <th>From Date</th> <th>To Date</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td align='center'>" . $row['DateFrom'] . "</td>"; echo "<td align='center'>" . $row['DateTo'] . "</td>"; echo "<td><input name=\"ID\" type=\"hidden\" value=\"" . $row['ID'] . "\"></td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Right below this code on the same searchresults.php page is the following form for the user to complete: HTML Code: <form action="comments.php" method="post" id="formstyle"> <textarea cols="20" name="comments" rows="2"></textarea><br /> <br /> <input name="Submit1" type="submit" value="Submit" /></form> The form is processed by comments.php which submits the results to the Feedback mysql table: comments.php PHP Code: <?php $con = mysql_connect("localhost","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("", $con); $sql="INSERT INTO feedback (VID, Comments) VALUES ('$_POST[iD]','$_POST[comments]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } header("Location: post_advice.htm"); mysql_close($con) ?> I have searched books, websites and forums for help but have not been able to find anything to help. I’m thinking it’s not possible to do this, but if someone can tell me it’s not possible, I might finally get the message! Thank you in advance for your assistance. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.