Jump to content

does the $_POST command work differently in a popup spawned by a Javascript?


texmansru47

Recommended Posts

This may be a stupid question, but I am seeing some weird results.  I have a form with PHP code behind it to get two values for my database.  I run a search from a value passed from the parent form and it works, and the INSERT INTO command takes that data no problem into the proper table, but the two values that the popup require the User to enter are not being posted to the database. 

 

Here is the code I have thus far:

 

<form method="POST" name="Recv" action="entry.php">

<table width="400" border="0" cellspacing="2" cellpadding="3">
  <tr>
    <td colspan="2" bgcolor="#000000"><span class="style1">Recv Control</span></td>
  </tr>
  <tr>
    <td bgcolor="#FFCC66">Serial Number: </td>
    <td bgcolor="#CCCCCC"><input name="SerNum" type="text" id="SerNum"></td>
  </tr>
  <tr>
    <td width="135" bgcolor="#FFCC66">Asset Number:</td>
    <td width="300" bgcolor="#CCCCCC"><input name="ProdNum" type="text" id="ProdNum"></td>
  </tr>
    <tr>
    <td> </td>
    <td><input type="submit" value="Submit" /></td>
  </tr>
</table>

</form>

<?php

$BatchNumData=$_GET['param1']; 
echo "Your Batch Number is:\n$BatchNumData";

// Connect to mysql database
$con = mysql_connect("localhost","users","xxxx") or die('Connection: ' . mysql_error());;
mysql_select_db("snatest", $con) or die('Database: ' . mysql_error());

// Insert form values into database
$copy = mysql_fetch_array(mysql_query("SELECT * FROM `batch` WHERE `BatchNum`= '$BatchNumData'")) or die(mysql_error()); 
// ^^ SELECT THE DATA TO BE COPIED ^^ 

@mysql_query("INSERT INTO `recv` (`BatchNum`, `1Num`, `SerNum`, `ProdNum`, `ModelSku`, `ModelType`, `DateRecv`) VALUES ('" . $copy['BatchNum'] . "', '" . $copy['1Num'] . "', '" . $_POST[serNum] ."', '" . $_POST[ProdNum] ."', '". $copy['Sku'] ."', '". $copy['Type'] ."', Now())") or die(mysql_error()); 
                
mysql_close($con);


?>


 

The two $_POST commands do not seem to be working, since in the database these values are blank.  I use the same code for a standard form I have and it works fine.  So would the $_POST commands work differently atfer being spawned by a javascript?

 

Just cannot figure it out.

 

Thanks,

 

Texman

Do you mean the single '?  I read that somewhere to do that... not sure why.  I'm self teaching myself php so I gather my data from tutorials, books and and these forums.  I see what the problem seems to be is that when the popup is opened, I get a record in my database without even typing in data.  Anyone had a cure for that?

 

Sound even crazier than my first question. 

 

But it seems when the popup entry form is opened, it generates a record... with blanks for my two values required. 

Here is what I got:

 

<html>
<head>
<title>Receiving - Part Two</title>
</head>

<body bgcolor="#C0C0C0">
<b><img border="0" src="logo1.jpg" width="45" height="44"> 
<font face="Arial" color="#000080">Product Entry</font></b><font face="Arial" color="#000080">
<hr>

<P>
<form method="POST" name="Recv" action="entry.php">

<table width="400" border="0" cellspacing="2" cellpadding="3">
  <tr>
    <td colspan="2" bgcolor="#000000"><span class="style1">Receiving</span></td>
  </tr>
  <tr>
    <td bgcolor="#FFCC66">Serial Number: </td>
    <td bgcolor="#CCCCCC"><input name="SerNum" type="text" id="SerNum"></td>
  </tr>
  <tr>
    <td width="135" bgcolor="#FFCC66">Asset Number:</td>
    <td width="300" bgcolor="#CCCCCC"><input name="ProdNum" type="text" id="ProdNum"></td>
  </tr>
    <tr>
    <td> </td>
    <td><input type="submit" value="submit" name="submit" /></td>
  </tr>
</table>

</form>

<?php
if (isset($_POST['submit'])) { 

$BatchNumData=$_GET['param1']; 
echo "Your Batch Number is:\n$BatchNumData";

// Connect to mysql database
$con = mysql_connect("localhost","user","xxxxx") or die('Connection: ' . mysql_error());;
mysql_select_db("test", $con) or die('Database: ' . mysql_error());


// Insert form values into database
$copy = mysql_fetch_array(mysql_query("SELECT * FROM `batch` WHERE `BatchNum`= '$BatchNumData'")) or die(mysql_error()); 
// ^^ SELECT THE DATA TO BE COPIED ^^ 

@mysql_query("INSERT INTO `recv` (`BatchNum`, `1Num`, `SerNum`, `ProdNum`, `ModelSku`, `ModelType`, `DateRecv`) VALUES ('" . $copy['BatchNum'] . "', '" . $copy['RTSNum'] . "', '" . $_POST[serNum] ."', '" . $_POST[ProdNum] ."', '". $copy['Sku'] ."', '". $copy['ModelType'] ."', Now())") or die(mysql_error()); 
                
mysql_close($con);
}
?>

</body>
</html>

 

Without your additional code (the if statement) I get a blank record in my database of "0" value for the ProdNum and a blank for the SerNum but I get the proper value of from the SELECT command and INSERT (the $copy variables).  I don't understand why this form is processing without any interaction from me.  This code is the code from the parent form that calls this popup (javascript involved):

 

<head>
<title>Receiving</title>
</head>

<body bgcolor="#CCCCCC">
<b><img border="0" src="logo1.jpg" width="78" height="77"> 
<font face="Arial" color="#000080">Receiving - Part One</font></b><font face="Arial" color="#000080">
<P>

<form method="POST" name="Recv" action="recvbatch.php"> 
<table width="550" border="0" cellspacing="2" cellpadding="3">
  <tr>
    <td colspan="2" bgcolor="#000000"><span class="style1">Batch/RA Receiving Start</span></td>
  </tr>
  <tr>
    <td bgcolor="#FFCC66">RA Number: </td>
    <td bgcolor="#CCCCCC"><input name="BatchNum" type="text" id="BatchNum"></td>
  </tr>
  <tr>
    <td> </td>
    <td><input type="submit" value="Submit Batch Request" /></td>
  </tr>
</table>

</form>
</body>
<center>
<hr>
<table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000">
<tr>
<td width="140" align="center"><b>RA Number</b></td>
<td width="130" align="center"><b>Prod Number</b></td>
<td width="75" align="center"><b>KU</b></td>
<td width="140" align="center"><b>Type of Repair</b></td>
<td width="140" align="center"><b>Model</b></td>
<td width="60" align="center"><b>Qty</b></td>
<td width="140" align="center"><b>Model Type</b></td>
<td width="130" align="center"><b>Received Date</b></td>
</tr>

<?php

error_reporting(E_ERROR | E_WARNING | E_PARSE);  

$con = mysql_connect("localhost","users","xxxx") or die('Connection: ' . mysql_error());;
mysql_select_db("test", $con) or die('Database: ' . mysql_error());
?><?
$sql = "SELECT * FROM `batch` WHERE `BatchNum`= '$_POST[batchNum]'";
$results = mysql_query($sql);
if ($results) { //this will check if the query failed or not
if (mysql_num_rows($results) > 0) {  //this will check if results were returned
    while($copy = mysql_fetch_array($results)) {
      	$variable1=$copy['BatchNum'];
      	$variable2=$copy['1Num'];
$variable3=$copy['Sku'];
$variable4=$copy['Type'];
$variable5=$copy['Model'];
$variable6=$copy['Qty'];
$variable7=$copy['ModelID'];
$variable8=$copy['RecvDate'];
//table layout for results

	print ("<tr>");
        print ("<td>$variable1</td>");		
	print ("<td>$variable2</td>");
	print ("<td>$variable3</td>");
	print ("<td>$variable4</td>");
	print ("<td>$variable5</td>");
	print ("<td>$variable6</td>");
	print ("<td>$variable7</td>");
	print ("<td>$variable8</td>");
	print ("</tr>");    }
  } else {
    echo "No results returned";
  }
} else {
  echo "Query error: ".mysql_error();
}

$batch1 = $variable1;
mysql_close($con);
?>
</table>  

<script language="JavaScript" type="Text/JavaScript">
//Will call the popup Window for Product Entry.

var fifteenth;var sixteenth;var seventeenth;
function eighteenth(nineteenth,twentieth) {
seventeenth=eval("document.getElementById('"+nineteenth+"')");sixteenth=twentieth;fifteenth=seventeenth.childNodes[0].nodeValue;seventeenth.childNodes[0].nodeValue=twentieth;}
function first2() { 
seventeenth.childNodes[0].nodeValue=fifteenth;}
</script>

</center>

<center>

<script>
<!--
function openpopup(url, windowtarget) 
{
    window.open(
        url, 
        windowtarget,
        'width=570,height=290,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0');
}
// -->
</script>

<a href="entry.php?param1=<?php echo $batch1; ?>"  
   target="entry"
   OnClick="openpopup(this.href, 'entry'); 
            return false;">Entry Screen</a>


</center>

<p><a href="receiving.html">Return to Main Receiving Page</a></p>

 

I hope this helps,

 

Texman

Yes I did... The form comes up and I can enter data, but nothing is written to the database.  Before that IF statement, the data from the SELECT query is put in, but the $_POST inputs are still not working.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.