I have 2 PHP pages...
INDEX.PHP with this code:
<form method="post" action="" name="f1">
<input type="text" name='p_name' size='50'><br>
<input type="text" name='p_name2' size='50'><br>
<a href="javascript:void(0);" NAME="My Window Name" title=" My title here " onClick=window.open("index2.php","Ratting","width=550,height=170,left=150,top=200,toolbar=1,status=1,");>Click here to open the child window</a>
</form>
and INDEX2.PHP with this avascript code:
<script langauge="javascript">
function post_value()
{
opener.document.f1.p_name.value = document.frm.c_name.value;
opener.document.f1.p_name2.value = document.frm.c_name2.value;
self.close();
}
</script>
and this PHP/HTML:
<form name="frm" method="post" action="">
<?php
$sql="SELECT * from customer";
$rs=mysql_query($sql,$conn) or die(mysql_error());
while($result=mysql_fetch_array($rs))
{
echo '<input type="text" name="c_name" size="50" value="'.$result["sequence"].'" /><br>
<input type="text" name="c_name2" size="50" value="'.$result["company"].'" /><br>
<input type=button value=\'Submit\' onclick=\'post_value();\'><br><br>';
}
?>
</form>
basically, when you go to index.php, you click the link to open the popup window index2.php and that then lists customers from a database and gives each one 2 text boxes - one for the sequence/id of the customer and the other for the company name and one submit button per row.
When the button is pressed, it runs the javascript function post_value(); which puts the values from the database/child popup window (index2.php) into the text boxes in the parent window (index.php)
when i run this code, it just puts the word undefined in box boxes on the parent page, however if i remove the while loop in php and it just displays the one row from the database of customers it works fine.
its like it doesn't like the while loop in php but i cannot work out why. any help would be much appreciated.
mysql_*functions to write new code. They are no longer maintained and the community has begun the deprecation process. See the red box? Instead you should learn about prepared statements and use either PDO or MySQLi. If you pick PDO here is a good tutorial.