Jump to content

[SOLVED] how to pass variables from main form URL to a javascript popup


texmansru47

Recommended Posts

I have a main php form that runs a query to pull data from a table in a database... that works find.  However I need to call the main variable (the Batch Number) from that search into a javascript popup I call.  The problem is the variable is not pulling over.

 

Here is what I have for the $_GET code:

 

<?php 

$BatchData=$_GET['variable1']; // - this is the call to get the data from the main form

// Connect to mysql database 
$con = mysql_connect("localhost","NAME","XXXX") or die('Connection: ' . mysql_error());; 
mysql_select_db("stest", $con) or die('Database: ' . mysql_error()); 
  
  
$grabit = "SELECT * FROM `batch` WHERE `BatchNum`= '$BatchData'"; 
$gotit = mysql_query($grabit) or die('Query Error: ' . mysql_error()); 
$copy = mysql_fetch_array($gotit); 
$sql = "INSERT INTO `snarecv` (SerNum, 1Num, BatchNum, 2Num, Sku, Type, DateRecv)  
VALUES ('$_POST[serNum]', '$_POST[1Num]', '" .$grabit[batchNum] ."', '" .$grabit[2Num] . "', '" .$grabit[sku] . "', '" .$grabit[Type] ."', Now())"; 
$result = mysql_query($sql) or die('Query Error: ' . mysql_error()); 
$copy = mysql_fetch_array($result);       
echo "<br>Quantity required is:\n$grabit[QTY]"; 
mysql_close($con); 
?> 

 

Here is where the variable is coming from:

 

$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['2Num'];
$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>");  // This is the variable in question		
            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();
}
      

 

I keep getting no value.  What I have to do is pull this data over to the popup so the user can enter in serial numbers of the product they are receiving.  I only ask for the serial number, and this variable will be ran in a query to pull all the like data for that batch and insert it into the table and that same record as the serial number being entered.

 

I cannot see where I am wrong in pulling that variable over.

 

Any ideas?

 

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.