PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
zed420
Forum Commoner
Posts: 32 Joined: Wed Jun 04, 2008 11:24 am
Post
by zed420 » Mon Feb 09, 2009 3:45 am
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
Code: Select all
$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
Code: Select all
$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
Ziq
Forum Contributor
Posts: 194 Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh
Post
by Ziq » Mon Feb 09, 2009 5:45 am
Page 1
Code: Select all
<? echo" <input type=\"submit\" name=\"view\" id=\"view\" value=\"View Details\" onclick=\"open_win('employee_con2.php?employee_id=$employee_id');\" />" ?>
It's first time using the $employee_id variable. What do you want?
Are you sure that employee_id is not primary key for the table employee?
Code: Select all
$query = "SELECT * FROM employee WHERE employee_id = '$employee_id'";
P.S. Warning! This code is not secure from SQL-Injection.
zed420
Forum Commoner
Posts: 32 Joined: Wed Jun 04, 2008 11:24 am
Post
by zed420 » Mon Feb 09, 2009 6:47 am
Yes employee_id is the primary key of employee table. What I want is to check a checkbox of a record and hit a JavaScripted button that gives me a new window and detail of that record. I know its possible because i'm nearly there the only truble I'm having is, its not showing me the checked recored instead its keeps coming up with last record of the table.
thanks
Zed
Ziq
Forum Contributor
Posts: 194 Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh
Post
by Ziq » Mon Feb 09, 2009 7:38 am
Why are you using checkboxes? I think it's not usable. If someone select ten checkboxes and click on the button he get 10 windows at once. Maybe better to use button inside the loop for every employee?
In every iteration of the loop you rewrite the $employee_id. It explain why you have a last record then click on the button.
If employer_id is a primary key why are you using "while" loop?
zed420
Forum Commoner
Posts: 32 Joined: Wed Jun 04, 2008 11:24 am
Post
by zed420 » Tue Feb 10, 2009 10:45 am
You were absolutely right Ziq, I've used the radioboxs instead, this is what I ended up with some help off course. Its working.
Thanks for your help
Zed
Code: Select all
<?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);
}
</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>