redqueentoknightfour Posted October 13, 2014 Share Posted October 13, 2014 Hi everybody. So I tried to do some research on this and the answers I found were pretty complicated and hard for me (as a newbie) to understand. What I am trying to do is send the results of an HTML form (radio buttons) to more than one php script (currently name_BB1.php but I would also like to send it to name_2.php). Is there a simple way to do this? Is it even possible? All I need to pass from the script is the name of the department chosen (Music Books or Video) and the first script uses that information to access related databases. However the second script also needs to know the name of the department originally chosen and I don't know how to get that variable over there without asking the user a second time. HTML: <form action="name_BB1.php" method="POST"> </p>Which database would you like to select?<br \><br \> <input type="radio" name="choice" value="Music" />I want music!<br \> <input type="radio" name="choice" value="Books" />Give me books!<br \> <input type="radio" name="choice" value="Video" />I want to see videos!<br \><br \> <input type="submit" value="submit"> </p></form> Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/291603-passing-form-data-to-multiple-scripts/ Share on other sites More sharing options...
redqueentoknightfour Posted October 13, 2014 Author Share Posted October 13, 2014 (edited) I don't know how to edit my original post, but in case it matters, here are the two scripts. SCRIPT 1 <!doctype html public "-//W3C//DTD HTML 4.0 //EN"><html><head> <title>BB's Title Selection</title></head><body bgcolor="lavender"><font size=+1 face="nyala"><h1>Welcome to BB's Inventory</h1><?php //FILE : name_BB1.php //PROG : (My name) //PURP : This program takes data from name_form6.html and analyzes the corresponding database // for information to display to the user for further input, which will then be sent to name_BB2.php. //DEFINE VARIABLES $username = "root"; $password = "######"; $hostname = "localhost"; $id = array(); $count = 0; //EXTRACT DATA extract ($_POST); //CONNECT TO SERVER $link = mysqli_connect($hostname, $username, $password); if (!$link) { die('Not connected : ' . mysql_error()); } //ACTIVATE DATABASE $db_selected = mysqli_select_db($link, 'cpt283db'); if (!$db_selected) { die ('Can\'t use cpt283db : ' . mysql_error()); } //TEST CHOICE NOT EMPTY if (isset($choice)){ //DISPLAY DEPARTMENT echo "<h2>$choice department</h2>"; echo "For the department you have chosen we have listed below the available titles."; //SELECT PRODUCT $sql = "SELECT * from products WHERE department='$choice'"; //QUERY $result = mysqli_query($link, $sql) or die(mysql_error()); if (mysqli_num_rows($result) == 0){ echo "No results were found."; } //DISPLAY RESULTS echo "<table border='0' width=1200px> <tr> <th></th><th>ID</th><th>Entertainer/Author</th><th>Title</th><th>Media</th><th>Feature</th> </tr>"; //SEND DATA FOR SECOND QUERY echo "<form action='name_BB2.php' method='POST'>"; while($row = mysqli_fetch_assoc($result)){ $id[$count] = $row['ID']; echo "<tr>"; echo "<td> <input type='checkbox' name='ID[]' value='$id[$count]'/><br \> "; echo "<td align='center'>" . $row['ID'] . "</td>"; echo "<td align='center'>" . $row['entertainerauthor'] . "</td>"; echo "<td align='center'>" . $row['title'] . "</td>"; echo "<td align='center'>" . $row['media'] . "</td>"; echo "<td align='center'>" . $row['feature'] . "</td>"; echo "</tr>"; echo "<br>"; $count ++; } echo "</table>"; echo "<input type='submit' value='submit'>"; echo "</form>"; } else echo "You have not specified a department. Please press back on your browser to do so."; mysqli_close($link);?></font></body></html> SCRIPT 2 <!doctype html public "-//W3C//DTD HTML 4.0 //EN"><html><head> <title>BB's Order Summary</title></head><body bgcolor="lavender"><font size=+1 face="nyala"><h1>Selection Summary</h1><?php //FILE : name_BB2.php //PROG : (My name) //PURP : This program takes information from name_BB1.php and searches the corresponding databases // for information about the user's selection to display to the user. //DEFINE VARIABLES $username = "root"; $password = "######"; $hostname = "localhost"; extract ($_POST); $count = 0; echo "Thank you for your selections! Below, you will find a summary of your choices."; //CONNECT TO SERVER $link = mysqli_connect($hostname, $username, $password); if (!$link) { die('Not connected : ' . mysql_error()); } //ACTIVATE DATABASE $db_selected = mysqli_select_db($link, 'cpt283db'); if (!$db_selected) { die ('Can\'t use cpt283db : ' . mysql_error()); } //TEST IF CHOICE SELECTED if (isset($ID)){ $size = count($ID); //START TABLE echo "<table border='0' width=1200px><tr><th>ID</th><th>Entertainer/Author</th><th>Title</th> <th>Price</th><th>Units In Stock</th><th>Summary</th></tr>"; while ($count < $size){ //SELECT INVENTORY $sql = "SELECT * FROM prodinv LEFT JOIN products ON products.ID=prodinv.ID WHERE prodinv.ID=$ID[$count]"; //QUERY $result = mysqli_query($link, $sql) or die(mysql_error()); if (mysqli_num_rows($result) == 0){ echo "No results were found."; } //DISPLAY RESULTS while($row = mysqli_fetch_assoc($result)){ echo "<tr>"; echo "<td align='center'>" . $row['ID'] . "</td>"; echo "<td align='center'>" . $row['entertainerauthor'] . "</td>"; echo "<td align='center'>" . $row['title'] . "</td>"; echo "<td align='center'>" . $row['UnitPrice'] . "</td>"; echo "<td align='center'>" . $row['UnitsInStock'] . "</td>"; echo "<td align='center'>" . $row['summary'] . "</td>"; echo "</tr>"; echo "<br>"; } //REPEAT FOR EACH ID $count ++; }//END WHILE //END TABLE echo "</table>"; }//END IF else echo "You did not select any titles. If you wish to do so, please press the back button on your browser."; mysqli_close($link);?></font></body></html> Script 2 is where I want to also send the $choice variable. Thanks again. Please let me know if I'm posting this in the wrong place. Any advice is appreciated! Edited October 13, 2014 by redqueentoknightfour Quote Link to comment https://forums.phpfreaks.com/topic/291603-passing-form-data-to-multiple-scripts/#findComment-1493443 Share on other sites More sharing options...
Solution cyberRobot Posted October 13, 2014 Solution Share Posted October 13, 2014 You could pass them using hidden form fields. https://www.google.com/#q=html%20hidden%20field Quote Link to comment https://forums.phpfreaks.com/topic/291603-passing-form-data-to-multiple-scripts/#findComment-1493449 Share on other sites More sharing options...
redqueentoknightfour Posted October 13, 2014 Author Share Posted October 13, 2014 Oh wow...it's always the most simple answers we don't see. Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/291603-passing-form-data-to-multiple-scripts/#findComment-1493452 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.