-IDEAL SCENARIO-
I have some php code that takes user input from a form's "select" menu and sends the value selected to a mysql DB using an "insert" query. The list of values that the user selects, itself is pulled from the DB. The value that the user selects is shown to them in a popup window. The php code for inserting the selected value into the DB is in the popup. Once the insert query is done, the popup window refreshes its calling "opener" window and closes itself, and the user is back to the place where they clicked the "add" button and the newly added values are shown on this place. If the user want to add another value, the process is repeated...
For removing any of the value(s) from this same list of values which is populated using the above mentioned scenario, the user has the option of using "check boxes" on the form. The user ticks all the boxes next to the values that they want deleted and clicks the "Remove" button. The PHP then cycles through all the selected values and deletes them one by one using a "delete" query.
The user can add or remove values as many times as wanted, as described above.
-PROBLEM-
STEPS:
1-The user clicks the add button
-> show popup.
Code: Select all
<input name="btn_addu2lec" type="button" id="btn_addu2lec" onclick="show_popup('assign_u2lec_pop.php?lecid=<?php echo $LECID;?>','assgnu2lecPop')" value=" Add " />2-The user selects the required value from the drop down list, clicks add on the popup window
- > insert query executed, values added to the DB(confirmed from mysql command line prompt "mysql> select * from table", and the value is there).
Code: Select all
$result = @mysql_query("insert into R_LECR_UNIT (LECR_ID,UNIT_ID) values('$LECID','$_GET[select]')");->The calling parent window refreshed and the popup is closed
Code: Select all
die("<script>window.opener.location.reload();window.opener.scroll(20,20);window.close();</script>");4- The user selects the same value again(the one they just deleted in step-3) to add from the list by repeating step 1 and 2, but the value does not insert into the DB
5- The user selects another value and clicks remove, it is removed
6- Now the user tries to add the same value which they removed in step-3 and tried to add again in step-4 - now it WORKS!. The only difference factor being another value was deleted first (in step-5), other wise it doesnt work as in step 4.
The code
Code: Select all
<?php
include("DBheader.php");
$LECID = $_GET['lecid'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Assign Unit Administration Overhead</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<?php
if ($_GET['assignUnit'] == 'Assign')
{
$result = @mysql_query("insert into R_LECR_UNIT (LECR_ID,UNIT_ID) values('$LECID','$_GET[select]')");
if (!$result)
{
die("<p> Error in insert : " . mysql_error() . "</p>");
}
else
{
die("<script>window.opener.location.reload();window.opener.scroll(20,20);window.close();</script>");
}
}
else
{
?>
<body>
<form name="form1" id="form1" method="get" action="assign_u2lec_pop.php" onSubmit="return check_unit_exist()">
<?php echo "<input type='hidden' name='lecid' value='$LECID' />"; ?>
<table width="100%" border="1" bordercolor="#0000CC">
<tr>
<?php
$qrylec_name = @mysql_query("select FIRST_NAME,LAST_NAME from LECTURER where LECR_ID='$LECID'");
if (!$qrylec_name)
{
die("<p> Error in retrieving Lecturer name : " . mysql_error() . "</p>");
}
$lec_name = mysql_fetch_array($qrylec_name);
?>
<td>Unit Assignment for <strong><?php echo $lec_name[FIRST_NAME] . " " . $lec_name[LAST_NAME]; ?></strong>
</td>
</tr>
<tr>
<td><table width="100%" border="0">
<tr>
<td><table width="100%" border="0">
<tr>
<td width="8%">Select Unit</td>
<td width="16%"><select name="select">
<?php
$qry_units = @mysql_query("select * from UNITS");
if (!$qry_units)
{
die("<p> Error in retrieving Units : " . mysql_error() . "</p>");
}
while($row = mysql_fetch_array($qry_units))
{
echo "
<option value='$row[UNIT_ID]'>$row[UNIT_NAME]</option>
";
}
?>
</select></td>
<td width="76%"> </td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" border="0">
<tr>
<td width="45%"><div align="right">
<input name="assignUnit" type="submit" id="assignUnit" value="Assign" />
</div></td>
<td width="55%"><input type="button" name="cancel" value="Cancel" onClick="window.close();"/></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>
<?php }
?>The only thing that makes it work is when the following line is removed
Code: Select all
die("<script>window.opener.location.reload();window.opener.scroll(20,20);window.close();</script>");but this causes the system not to refresh the calling parent window, to show the updated values in the list and close the popup window, which is the core requirement.
It was working fine a couple of days back, and the only change done was changing the datatype of a column in the MySQL DB from and 'int' to a 'varchar'. This is the LECR_ID column and the corresponding changes as required in the PHP code were done. I dont see the relation between this change and the problem, but thats only me, thought ill mention it here.
Any help will be highly highly appreciated.
Thanks in advance
Salman