zed420 Posted February 9, 2009 Share Posted February 9, 2009 Hi all I hope someone can help me, I’m trying to open another page by using checkboxes and JavaScript on a Button. JavaScript is fine it opens up a new page but I can NOT seem to take the checked link, it keeps on opening the last record even thou I’m checking different record. How the hell do I do it? Thanks in advance. Page 1 $query = "SELECT * FROM employee ORDER BY last_name"; $result = mysql_query($query)or die(mysql_error()); ?> <div class="medText"> <b>list of Employees</b> <TABLE BORDER=0 WIDTH=100% CELLSPACING=3 CELLPADDING=3 ALIGN=CENTER bgcolor="#BFB5F9"> <TR bgcolor="#D7D6D2"> <td align=center><b>ID</b></TD> <td align=center><b>Date Reg </b></TD> <td align=center><b>Last name</b></TD> <td align=center><b>First name</b></TD> <td align=center><b>Address</b></TD> <td align=center><b>Town/City</b></TD> <td align=center><b>Home Tel</b></TD> <td align=center><b>Mobile Tel</b></TD> <td align=center><b>Status</b></TD> <td align=center></TD> </tr> <? while ($row = mysql_fetch_array($result)) { extract($row); echo "<tr class=\"td\"> <td>" . $row['employee_id'] . "</a></td> <td>" . $row['date_registered'] . "</td> <td>" . $row['last_name'] ."</td> <td>" . $row['first_name'] ."</td> <td>" . $row['address'] . "</td> <td>" . $row['town_city'] . "</td> <td>" . $row['home_no'] . "</td> <td>" . $row['mobile_no'] . "</td> <td>" . $row['status'] . "</td> <td>" ?> <input type="checkbox" name="<?=$row[employee_id]?>" id="<?=$row[employee_id]?>" value="<?=$row[employee_id]?>"/> <? "</TD> </tr>"; } ?> </TABLE> <br><center> <? echo" <input type=\"submit\" name=\"view\" id=\"view\" value=\"View Details\" onclick=\"open_win('employee_con2.php?employee_id=$employee_id');\" />" ?> </center> </div> Page2 $employee_id = $_GET['employee_id']; $query = "SELECT * FROM employee WHERE employee_id = '$employee_id'"; $result = mysql_query($query)or die(mysql_error()); while ($row = mysql_fetch_array($result)) { extract($row); ?> <p></p> <center><div id="display"> <?php echo $adminname ?> Your New Employee record has been inserted into the databes Successfully. Please check below for details. <p></p> <TABLE BORDER="0" WIDTH="100%" bgcolor="#CFFEFD"> <TR class="td" align="left"> <TH WIDTH="36%">Employee ID</TH> <TD WIDTH="64%"><?php echo $employee_id ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Employment required As</TH> <TD WIDTH="64%"><?php echo $employment_required ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Registration Date</TH> <TD WIDTH="64%"><?php echo $date_registered ?></TD> </TR> </table> <? } ?> Zed Link to comment https://forums.phpfreaks.com/topic/144460-solved-link-via-button-not-working/ Share on other sites More sharing options...
trq Posted February 9, 2009 Share Posted February 9, 2009 You need to use a form. By the time your code gets to here.... <?php echo" <input type=\"submit\" name=\"view\" id=\"view\" value=\"View Details\" onclick=\"open_win('employee_con2.php?employee_id=$employee_id');\" />" ?> $employee_id will obviously be the emplyee_id of the last record. Link to comment https://forums.phpfreaks.com/topic/144460-solved-link-via-button-not-working/#findComment-758016 Share on other sites More sharing options...
zed420 Posted February 9, 2009 Author Share Posted February 9, 2009 Thanks for the quick reply, I've tride what you've suggested it gives me a blank page. zed Link to comment https://forums.phpfreaks.com/topic/144460-solved-link-via-button-not-working/#findComment-758027 Share on other sites More sharing options...
trq Posted February 9, 2009 Share Posted February 9, 2009 Post your code. Link to comment https://forums.phpfreaks.com/topic/144460-solved-link-via-button-not-working/#findComment-758029 Share on other sites More sharing options...
zed420 Posted February 9, 2009 Author Share Posted February 9, 2009 <? session_start(); include('config.php'); $query = "SELECT * FROM employee ORDER BY last_name"; $result = mysql_query($query)or die(mysql_error()); ?> <div class="medText"> <form name="action" id="action" method="post" action="Test2.php"> <b>list of Employees</b> <TABLE BORDER=0 WIDTH=100% CELLSPACING=3 CELLPADDING=3 ALIGN=CENTER bgcolor="#BFB5F9"> <TR bgcolor="#D7D6D2"> <td align=center><b>ID</b></TD> <td align=center><b>Date Reg </b></TD> <td align=center><b>Last name</b></TD> <td align=center><b>First name</b></TD> <td align=center><b>Address</b></TD> <td align=center><b>Town/City</b></TD> <td align=center><b>Home Tel</b></TD> <td align=center><b>Mobile Tel</b></TD> <td align=center><b>Status</b></TD> <td align=center></TD> </tr> <? while ($row = mysql_fetch_array($result)) { extract($row); echo "<tr class=\"td\"> <td> <a href=\"javascript:open_win('detailNormal.php?employee_id=$employee_id');\"> " . $row['employee_id'] . "</a></td> <td>" . $row['date_registered'] . "</td> <td>" . $row['last_name'] ."</td> <td>" . $row['first_name'] ."</td> <td>" . $row['address'] . "</td> <td>" . $row['town_city'] . "</td> <td>" . $row['home_no'] . "</td> <td>" . $row['mobile_no'] . "</td> <td>" . $row['status'] . "</td> <td>" ?> <input type="checkbox" name="<?=$row[employee_id]?>" id="<?=$row[employee_id]?>" value="<?=$row[employee_id]?>"/> <? "</TD> </tr>"; } ?> </TABLE> <br><center> <? echo" <input type=\"submit\" name=\"view\" id=\"view\" value=\"View Details\" onclick=\"open_win('Test2.php?employee_id=$employee_id');\" />" ?> </center> </form></div> Page2 <? include('config.php'); $employee_id = $_GET['employee_id']; $query = "SELECT * FROM employee WHERE employee_id = '$employee_id'"; $result = mysql_query($query)or die(mysql_error()); while ($row = mysql_fetch_array($result)) { extract($row); ?> <TABLE BORDER="0" WIDTH="100%" bgcolor="#CFFEFD"> <TR class="td" align="left"> <TH WIDTH="36%">Employee ID</TH> <TD WIDTH="64%"><?php echo $employee_id ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Employment required As</TH> <TD WIDTH="64%"><?php echo $employment_required ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Registration Date</TH> <TD WIDTH="64%"><?php echo $date_registered ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Title</TH> <TD WIDTH="64%"><?php echo $title ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >First Name</TH> <TD WIDTH="64%"><?php echo $first_name ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Last Name</TH> <TD WIDTH="64%"><?php echo $last_name ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >D O B</TH> <TD WIDTH="64%"><?php echo $ni_no ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Name</TH> <TD WIDTH="64%"><?php echo $dob ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Address</TH> <TD WIDTH="64%"><?php echo $address ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Post Code</TH> <TD WIDTH="64%"><?php echo $town_city ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >County</TH> <TD WIDTH="64%"><?php echo $county ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Post Code</TH> <TD WIDTH="64%"><?php echo $postcode ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Home tel</TH> <TD WIDTH="64%"><?php echo $home_no ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Mobile</TH> <TD WIDTH="64%"><?php echo $mobile_no ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Date</TH> <TD WIDTH="64%"><?php echo $email ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Driving Licence</TH> <TD WIDTH="64%"><?php echo $nationality ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Time</TH> <TD WIDTH="64%"><?php echo $driving_licence ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Transport</TH> <TD WIDTH="64%"><?php echo $transport ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >ID Check</TH> <TD WIDTH="64%"><?php echo $id_check ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Birth Certificate</TH> <TD WIDTH="64%"><?php echo $birth_certificate ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >P45 NI Card</TH> <TD WIDTH="64%"><?php echo $p45_nicard ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Immigration Status</TH> <TD WIDTH="64%"><?php echo $immigration_status ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Bank Name</TH> <TD WIDTH="64%"><?php echo $bank_name ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Bank Address</TH> <TD WIDTH="64%"><?php echo $baddress ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Time</TH> <TD WIDTH="64%"><?php echo $btown ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Bank county</TH> <TD WIDTH="64%"><?php echo $bcounty ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Bank post Code</TH> <TD WIDTH="64%"><?php echo $bpostcode ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Account Name</TH> <TD WIDTH="64%"><?php echo $account_name ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Sort Code</TH> <TD WIDTH="64%"><?php echo $sort_code ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Time</TH> <TD WIDTH="64%"><?php echo $account_number ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Comments</TH> <TD WIDTH="64%"><?php echo htmlspecialchars($comments) ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Status</TH> <TD WIDTH="64%"><?php echo $status ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >W R S</TH> <TD WIDTH="64%"><?php echo $wrs ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Work Preference</TH> <TD WIDTH="64%"><?php echo $work_preference ?></TD> </TR> <TR class="td" align="left"> <TH WIDTH="36%" >Shift Preference</TH> <TD WIDTH="64%"><?php echo $shift_preference ?></TD> </TR> <? } ?> </TABLE> <p></p> </div></center> Link to comment https://forums.phpfreaks.com/topic/144460-solved-link-via-button-not-working/#findComment-758037 Share on other sites More sharing options...
trq Posted February 9, 2009 Share Posted February 9, 2009 Your form uses the post method, not point trying to get the value through $_GET as it will always be the last id. Link to comment https://forums.phpfreaks.com/topic/144460-solved-link-via-button-not-working/#findComment-758039 Share on other sites More sharing options...
zed420 Posted February 9, 2009 Author Share Posted February 9, 2009 Do you want me to use GET ?? Link to comment https://forums.phpfreaks.com/topic/144460-solved-link-via-button-not-working/#findComment-758042 Share on other sites More sharing options...
trq Posted February 9, 2009 Share Posted February 9, 2009 I think you need to look at some tutorials on forms and php. Your code is pretty well messed up. Theres a link in my sig (Hudzilla) that has a chapter on the subject. Link to comment https://forums.phpfreaks.com/topic/144460-solved-link-via-button-not-working/#findComment-758047 Share on other sites More sharing options...
zed420 Posted February 9, 2009 Author Share Posted February 9, 2009 Am I asking some thing impossible? Link to comment https://forums.phpfreaks.com/topic/144460-solved-link-via-button-not-working/#findComment-758052 Share on other sites More sharing options...
trq Posted February 9, 2009 Share Posted February 9, 2009 No not at all. I just don't think you have an understanding of what your code is doing. Link to comment https://forums.phpfreaks.com/topic/144460-solved-link-via-button-not-working/#findComment-758059 Share on other sites More sharing options...
sasa Posted February 9, 2009 Share Posted February 9, 2009 change <input type="checkbox" name="<?=$row[employee_id]?>" id="<?=$row[employee_id]?>" value="<?=$row[employee_id]?>"/> to <input type="checkbox" name="employee_id[]" id="<?=$row[employee_id]?>" value="<?=$row[employee_id]?>"/> and on page2 try to print_r($_POST['employee_id']); Link to comment https://forums.phpfreaks.com/topic/144460-solved-link-via-button-not-working/#findComment-758093 Share on other sites More sharing options...
zed420 Posted February 9, 2009 Author Share Posted February 9, 2009 Thank you everyone I managed it at the end with some help. <?php session_start(); ?> <html> <head> <title>Blank Page</title> </head> <body> <script type="text/Javascript"> var viewid=''; function updte(a){ viewid = a; } function op(){ mywindow = window.open('Test2.php?employee_id='+viewid); } function show_alert() { var msg = "Welcome to plus2net.com"; alert(msg); } function open_win(url_add) { mywindow = window.open(url_add,'Test','width=900,height=500,menubar=no,status=no,location=1,toolbar=no,scrollbars=yes'); mywindow.moveTo(50,80); } </script> <?php include('config.php'); $query = "SELECT * FROM employee ORDER BY last_name"; $result = mysql_query($query)or die(mysql_error()); ?> <div class="medText"> <b>list of Employees</b> <TABLE BORDER=0 WIDTH=100% CELLSPACING=3 CELLPADDING=3 ALIGN=CENTER bgcolor="#BFB5F9"> <TR bgcolor="#D7D6D2"> <td align=center><b>ID</b></TD> <td align=center><b>Last name</b></TD> <td align=center><b>First name</b></TD> <td> </td> </tr> <?php while ($row = mysql_fetch_array($result)) { extract($row); echo "<tr class=\"td\"> <td>" . $row['employee_id'] . "</td> <td>" . $row['date_registered'] . "</td> <td>" . $row['last_name'] ."</td> <td>" . $row['first_name'] ."</td> <td>" . $row['address'] . "</td> <td>" . $row['town_city'] . "</td> <td>" . $row['home_no'] . "</td> <td>" . $row['mobile_no'] . "</td> <td>" . $row['status'] . "</td> <td><input type='radio' onclick='updte(this.value);' name='emp' id='".$row['employee_id']."' value='".$row['employee_id']."'/></tr>"; } ?> </table> <br><center> <input type="submit" name="view" id="view" value="View Details" onClick="op();" > </center> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/144460-solved-link-via-button-not-working/#findComment-758182 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.