steveb1471 Posted August 25, 2020 Share Posted August 25, 2020 Hi i have a search page that pulls the results from 3 different tables within my database it is shows a snippet of each record with a submit button which shows the full record in a pop up form if the user decides to click on it. The problem i am having is that lets say for example the contract table pulls down 3 results, the button next to the snippet for the first result will open the desired pop up. However the button for the other 3 records directs to a different form for another table. Does anyone have any idea <?php require "header.php"; ?> <main> <link href="style.css" rel="stylesheet" type="text/css"> <script>storedata.js</script> <div class="wrapper-main"> <div class="welcomelogged1"> <p>Searching For A Starter<p> </div> <form action="" method="post"> <select name="WeekComm" id="WeekComm"> <option value="Enter Week No To Search">Enter Week No To Search</option> <option value="WC 6th April">WC 6th April</option> <option value="WC 13th April">WC 13th April</option> <option value="WC 20th April">WC 20th April</option> <option value="WC 27th April">WC 27th April</option> </select> <input type="submit" name="Search" value="Search Starters" style="color: #FFFFFF; font-weight: bold; background-color: #81BC47;"></td> <br> <br> <br> </form> <form class ="formrecpaye" name="formrecpaye" id="formrecpaye" target="print_popup" action="searchrecordpaye.php" method="POST" onsubmit="window.open('searchrecordpaye.php','print_popup','width=1500,height=950');"> <table> <th class="resulttitle" colspan="8" style="text-align: center"><label name="Paye">PAYE New Starters</label></th> <Tr> <th class="blank"> </th> <th width="175px">Week Commencing</th> <th width="175px">First Name</th> <th width="175px">Last Name</th> <th width="175px">Consultant</th> <th width="150px">Start Date</th> <th width="175px">Client Name</th> <th width="130px">Action</th> </Tr> <?php require 'includes/dbh.inc.php'; if (isset($_POST['Search'])) { $WeekComm = $_POST['WeekComm']; $query = "SELECT * FROM paye where WeekComm='$WeekComm' "; $query_run = mysqli_query($conn,$query); while($row = mysqli_fetch_array($query_run)) { ?> <tr> <td align="center"><input readonly width="175px" type="hidden" name="id" value="<?php echo $row['id'] ?>"></td> <td align="center"><input readonly width="175px" type="text" name="WeekComm" value="<?php echo $row['WeekComm'] ?>"></td> <td align="center"><input readonly width="175px" type="text" name="FirstName" value="<?php echo $row['FirstName'] ?>"></td> <td align="center"><input readonly width="175px" type="text" name="LastName" value="<?php echo $row['LastName'] ?>"></td> <td align="center"><input readonly width="175px" type="text" name="Consultant" value="<?php echo $row['Consultant'] ?>"></td> <td align="center"><input readonly width="150px" type="date" name="StartDate" value="<?php echo $row['StartDate'] ?>"></td> <td align="center"><input readonly width="175px" type="text" name="ClientName"value="<?php echo $row['ClientName'] ?>"></td> <td align="center"><input type="submit" name="showdata1" action="searchrecordpaye.php" onclick="storedata()" value="View Record" style="color: #FFFFFF; font-weight: bold; background-color: #81BC47;"></td> </tr> </form> <?php } } ?> <form class ="formreccon" name="formreccon" id="formreccon" target="print_popup" action="searchrecordcon.php" method="POST" onsubmit="window.open('searchrecordcon.php','print_popup','width=1500,height=950');"> <table> <th class="resulttitle" colspan="8" style="text-align: center"><label name="ContractResultTitel">Contract New Starters</label></th> <Tr><th class="blank"> </th> <th width="175px">Week Commencing</th> <th width="175px">First Name</th> <th width="175px">Last Name</th> <th width="175px">Consultant</th> <th width="150px">Start Date</th> <th width="175px">Client Name</th> <th width="130px">Action</th> </Tr> <?php require 'includes/dbh.inc.php'; if (isset($_POST['Search'])) { $WeekComm = $_POST['WeekComm']; $query = "SELECT * FROM contract where WeekComm='$WeekComm' "; $query_run = mysqli_query($conn,$query); while($row = mysqli_fetch_array($query_run)) { ?> <tr> <td align="center"><input readonly width="175px" type="hidden" name="id" value="<?php echo $row['id'] ?>"></td> <td align="center"><input readonly width="175px" type="text" name="WeekComm" value="<?php echo $row['WeekComm'] ?>"></td> <td align="center"><input readonly width="175px" type="text" name="FirstName" value="<?php echo $row['FirstName'] ?>"></td> <td align="center"><input readonly width="175px" type="text" name="LastName" value="<?php echo $row['LastName'] ?>"></td> <td align="center"><input readonly width="175px" type="text" name="Consultant" value="<?php echo $row['Consultant'] ?>"></td> <td align="center"><input readonly width="150px" type="date" name="StartDate" value="<?php echo $row['StartDate'] ?>"></td> <td align="center"><input readonly width="175px" type="text" name="ClientName"value="<?php echo $row['ClientName'] ?>"></td> <td align="center"><input type="submit" name="showdata2" action="searchrecordcon.php" onclick="storedata()" value="View Record" style="color: #FFFFFF; font-weight: bold; background-color: #81BC47;"></td> </tr> </form> <?php } } ?> <form class ="formrecperm" name="formrecperm" id="formrecperm" target="print_popup" action="searchrecordperm.php" method="POST" onsubmit="window.open('searchrecordperm.php','print_popup','width=1500,height=950');"> <table> <th class="resulttitle" colspan="8" style="text-align: center"><label name="PermResultTitel">Permanent New Starters</label></th> <Tr> <th class="blank"> </th> <th width="175px">Week Commencing</th> <th width="175px">First Name</th> <th width="175px">Last Name</th> <th width="175px">Consultant</th> <th width="150px">Start Date</th> <th width="175px">Client Name</th> <th width="130px">Action</th> </Tr> <?php require 'includes/dbh.inc.php'; if (isset($_POST['Search'])) { $WeekComm = $_POST['WeekComm']; $query = "SELECT * FROM permanent where WeekComm='$WeekComm' "; $query_run = mysqli_query($conn,$query); while($row = mysqli_fetch_array($query_run)) { ?> <tr> <td align="center"><input readonly width="175px" type="hidden" name="id" value="<?php echo $row['id'] ?>"></td> <td align="center"><input readonly width="175px" type="text" name="WeekComm" value="<?php echo $row['WeekComm'] ?>"></td> <td align="center"><input readonly width="175px" type="text" name="FirstName" value="<?php echo $row['FirstName'] ?>"></td> <td align="center"><input readonly width="175px" type="text" name="LastName" value="<?php echo $row['LastName'] ?>"></td> <td align="center"><input readonly width="175px" type="text" name="Consultant" value="<?php echo $row['Consultant'] ?>"></td> <td align="center"><input readonly width="150px" type="date" name="StartDate" value="<?php echo $row['StartDate'] ?>"></td> <td align="center"><input readonly width="175px" type="text" name="ClientName"value="<?php echo $row['ClientName'] ?>"></td> <td align="center"><input type="submit" name="showdata3" action="searchrecordperm.php" onclick="storedata()" value="View Record" style="color: #FFFFFF; font-weight: bold; background-color: #81BC47;"></td> </tr> </form> <?php } } ?> as standard the page displays like this if i click on the 2nd result down on "contract new starters" a pop up windows opens with the address http://localhost/loginsystem/searchrecordpaye.php when i should be directed to http://localhost/loginsystem/searchrecordcon.php I am directed here if i select the first result in the list has anyone any ideas? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/311386-view-records-button/ Share on other sites More sharing options...
NotSunfighter Posted August 26, 2020 Share Posted August 26, 2020 I would like to see the JavaScript => storedata() Quote Link to comment https://forums.phpfreaks.com/topic/311386-view-records-button/#findComment-1580965 Share on other sites More sharing options...
Barand Posted August 26, 2020 Share Posted August 26, 2020 Why have you got three tables with the same apparent structure instead of a single table with an extra column to indicate paye/contract/permanent? Quote Link to comment https://forums.phpfreaks.com/topic/311386-view-records-button/#findComment-1580966 Share on other sites More sharing options...
steveb1471 Posted August 26, 2020 Author Share Posted August 26, 2020 8 hours ago, NotSunfighter said: I would like to see the JavaScript => storedata() The script is to keep the original data on the page when the submit button is pressed function storedata() { if(typeof(Storage) !== "undefined") { var WeekComm = document.getElementById("WeekComm").value; if (sessionStorage.WeekComm) { document.getElementById("WeekComm").value = WeekComm; } else { sessionStorage.WeekComm = WeekComm; } document.getElementById("res").innerHTML = "Your datas restored"; } else { document.getElementById("res").innerHTML = "Sorry, your browser does not support web storage..."; } } Quote Link to comment https://forums.phpfreaks.com/topic/311386-view-records-button/#findComment-1580973 Share on other sites More sharing options...
steveb1471 Posted August 26, 2020 Author Share Posted August 26, 2020 8 hours ago, Barand said: Why have you got three tables with the same apparent structure instead of a single table with an extra column to indicate paye/contract/permanent? hi, thanks for the reply the structure of the 3 tables differ greatly, just share the 5/6 column names. Quote Link to comment https://forums.phpfreaks.com/topic/311386-view-records-button/#findComment-1580974 Share on other sites More sharing options...
steveb1471 Posted August 26, 2020 Author Share Posted August 26, 2020 anyone any ideas? thanks steve Quote Link to comment https://forums.phpfreaks.com/topic/311386-view-records-button/#findComment-1580982 Share on other sites More sharing options...
mac_gyver Posted August 26, 2020 Share Posted August 26, 2020 the html markup has a number of mistakes - some missing <tr></tr> tags, no closing </table> tags, and opening/closing <form></form> tags in the wrong places. this last item is probably what's causing the wrong operation. you should validate the html of the resulting page at validator.w3.org for what you are apparently doing, a 'view more' link, just use a button as a html link, with a type id (paye/contract/permanent) and a record id as get parameters in the link. there's really no need for the post method forms (and the search form should use method = 'get'.) Quote Link to comment https://forums.phpfreaks.com/topic/311386-view-records-button/#findComment-1580985 Share on other sites More sharing options...
steveb1471 Posted August 26, 2020 Author Share Posted August 26, 2020 Hi Thank you for the reply I have tried closing the </table> tags but with the table being closed it limits my results to one record Where have i gone wrong with the location of the <form></form> tags? Sorry if i am asking sill questions but i am keen to learn. thanks Quote Link to comment https://forums.phpfreaks.com/topic/311386-view-records-button/#findComment-1580989 Share on other sites More sharing options...
mac_gyver Posted August 27, 2020 Share Posted August 27, 2020 11 hours ago, steveb1471 said: I have tried closing the </table> tags but with the table being closed it limits my results to one record you need to define what output your code is going to produce (before you write the code.) if each of the three sections of data is to be a separate html table, you need an opening <table> tag at the start of each table and a closing </table> tag after you have output all the <tr> ... </tr> rows in the table. we cannot help you with any problem with code you tried unless you post that code. 11 hours ago, steveb1471 said: Where have i gone wrong with the location of the <form></form> tags? you have one opening <form ...> tag for each of the three sections of data, but you are outputting a closing </form> tag inside the data loop. after the 1st closing </form> tag, for the 1st row of data, the browser doesn't have any idea what the rest of the form fields and submit buttons are for. are you sure you even need/want forms for this part of the output? why are you even outputting the data values in readonly form fields? Quote Link to comment https://forums.phpfreaks.com/topic/311386-view-records-button/#findComment-1581000 Share on other sites More sharing options...
steveb1471 Posted August 27, 2020 Author Share Posted August 27, 2020 Thank you for the reply I have taken your comments on board and have tried to make things a little simpler whist at stage of my development. when the users selects a certain 'WeekComm' the result could produce 4/5 rows looking something like this id: 1 Name: John smith id: 2 Name: Steve Jones id: 3 Name: Dave Smith id: 4 Name: Andrew Smith These 4 fields are just a very small part of the whole record for that row. Is it possible for there to be a more details link on each result which i could direct to a different page showing the complete record by capturing the id of that result? Below is the new code <?php require "header.php"; ?> <main> <link href="style.css" rel="stylesheet" type="text/css"> <div class="wrapper-main"> <div class="welcomelogged1"> <p>Searching For A Starter<p> </div> <body> <form action="" method="GET"> <select name="WeekComm" id="WeekComm"> <option value="Enter Week No To Search">Enter Week No To Search</option> <option value="WC 6th April">WC 6th April</option> <option value="WC 13th April">WC 13th April</option> <option value="WC 20th April">WC 20th April</option> <option value="WC 27th April">WC 27th April</option> </select> <input type="submit" name="Search" value="Search Starters"> <br> <br> <br> </form> <form class ="formrecpaye" name="formrecpaye" id="formrecpaye" action="" method="GET"> <table> <div> <th class="175px">Id</th> <th width="175px">Week Commencing</th> <th width="175px">First Name</th> <th width="175px">Last Name</th> <th width="130px">Action</th> </div> </table> <?php require 'includes/dbh.inc.php'; $WeekComm = $_GET['WeekComm']; $query = "SELECT * FROM contract where WeekComm='$WeekComm' "; $query_run = mysqli_query($conn,$query); if (mysqli_num_rows($query_run) > 0) { while($row = mysqli_fetch_assoc($query_run)) { echo "id: " . $row["id"]. "Name: " . $row["FirstName"]. "" . $row["LastName"]. "<br>"; } } else { echo "0 results"; } mysqli_close($conn); ?> </form> </body> </div> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/311386-view-records-button/#findComment-1581003 Share on other sites More sharing options...
NotSunfighter Posted August 27, 2020 Share Posted August 27, 2020 (edited) @steveb1471, This is way more complicated then it should be. I see a hard time ahead maintaining this with uodates or repairs. IMHO I'd use AJAX to communicate this your PHP and DB. storedata() works with sessionStorage and has nothing to do with communication and adds extra steps to what your doing. The SELECT should be user INPUT, because it needs to be upgraded by a programmer when new weeks appear. The worst thing I see is the unneeded use of FORM to talk to PHP. Ajax does this nicely and will open a POP UP BOX and display your information without ruining the HTML page. Please consider AJAX. Edited August 27, 2020 by NotSunfighter Quote Link to comment https://forums.phpfreaks.com/topic/311386-view-records-button/#findComment-1581010 Share on other sites More sharing options...
bakertaylor28 Posted September 4, 2020 Share Posted September 4, 2020 (edited) Following the KISS principle, The way I would handle this is to have each button submit to a different php script and do a header redirect if need be. This approach is particularly useful if you can't use mod_rewrite such as if you're using nginx. Edited September 4, 2020 by bakertaylor28 clarification Quote Link to comment https://forums.phpfreaks.com/topic/311386-view-records-button/#findComment-1581134 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.