Passing Array from PopUp to DB

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

Post Reply
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Passing Array from PopUp to DB

Post by facets »

Hi All,

I'm having some grief trying to pass an array from a popUp form to MySql.
It's creating a new record but all entries are blank.

Any ideas?
Tia, Wil.

Code: Select all

<?
 $action = ($_GET['action']);

// Set Up Submit 
    if ($_POST['submit']) {
        echo '<pre>'; print_r($_POST); echo "<h1>Submitted to DB</h1><br>"; echo "</pre>";
        } 

// Add function
function fnAddFaceStock() {

html_header();

$description = $_GET['description'];
$basisWeight = $_GET['basisWeight'];
$wetTensileStrenghtCD = $_GET['wetTensileStrenghtCD'];
$wetTensileStrenghtMD = $_GET['wetTensileStrenghtMD'];
$dryTensileStrengthCD = $_GET['dryTensileStrengthCD'];
$dryTensileStrengthMD = $_GET['dryTensileStrengthMD'];

$sql_add = "INSERT INTO austock values('','$description','$basisWeight','','$wetTensileStrenghtCD',
'$wetTensileStrenghtMD','$dryTensileStrengthCD','$dryTensileStrengthMD','',
'','','','','','','','','','','','')";

mysql_query($sql_add) or die(mysql_error());

?>

<form method='post' action='<? echo $_SERVER['PHP_SELF']; ?>'>
<input type='hidden' name='commented' value='set'>
<? 

	echo "<table class=\"materials\"><tr>";

	$createFaceStockSpec=array('Description','Basis Weight','Caliper','Wet Tensile Strength CD','Wet Tensile Strength MD',
	'Dry Tensile Strength CD','Dry Tensile Strength MD','Opacity','Gloss','Brightness','Moisture Content','Relative Humidity',
	'Absorption','Smoothness','Tear Strength CD','Tear Strength MD','Burst Strength','PH');

	$enter = array('description','basisWeight','caliper','wetTensileStrenghtCD','wetTensileStrenghtMD',
	'dryTensileStrengthCD','dryTensileStrengthMD','opacity','gloss','brightness','moistureContent','relativeHumitity',
	'absorbtion','smoothness','tearStrengthCD','tearStrengthMD','burstStrength','pH');
	
	for($x = 0; $x<count($createFaceStockSpec); $x++) {
  		echo "<tr><td width=\"200px\" colspan=\"2\" valign=\"top\">".$createFaceStockSpec[$x]."</td>\n";
  		echo "<td width=\"200px\" colspan=\"2\"><input type=\"text\" name=\"".$enter[$x]."\" SIZE=\"20\"></td></tr>\n";
		}
	
	?>
	<tr><td width=100px colspan=2 valign=top><input type='reset' class='btn' value='Reset Face Stock'></td>
	<td width=100px colspan=3><input type='submit' class='btn' name='something' value='Add Face Stock'></td></tr>
	</form>
<?
}
?>
josh-j
Forum Newbie
Posts: 4
Joined: Thu May 12, 2005 8:49 pm
Location: melbourne, australia

Re: Passing Array from PopUp to DB

Post by josh-j »

Facet,

Since you've set the method of your form to "post", you should be using $_POST[...] instead of $_GET[...]
facets wrote:

Code: Select all

$description = $_GET['description'];
$basisWeight = $_GET['basisWeight'];
$wetTensileStrenghtCD = $_GET[
...etc.
If you need to keep open the possibility of receiving data from GET as well as POST, then use $_REQUEST[...] instead.

Hope that helps.

- - josh
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post by facets »

Thanks for the reply Josh.
Still no data being passed even with the _POST line.
I'm guessing it's my $action command or perhaps my sql line.

Any other ideas?

Cheers, Wil/
josh-j
Forum Newbie
Posts: 4
Joined: Thu May 12, 2005 8:49 pm
Location: melbourne, australia

Re: Passing Array from PopUp to DB

Post by josh-j »

Wil, Might help to try this

Code: Select all

echo '<pre>';
var_dump($_GET);
var_dump($_POST);
echo '</pre>';
right before your sql query, just to check if the values are actually coming through. If not, insert this code at a few other points between data entry & executing the query to find out where the data is getting lost.
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post by facets »

When I popup the window I get
array(1) {
["action"]=>
string(16) "viewAddFaceStock"
}
array(0) {
}
Also, All my variables are displaying :
Notice: Undefined index: description in c:\program files\easyphp1-8\www\materialsregister\auaddsummary.php on line 258

or similar. Which doesn't happen on the parent page.

Any ideas?
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post by facets »

This is output after the submit button is clicked.
It also reloads the main function (page).
array(0) {
}
array(19) {
["commented"]=>
string(3) "set"
["description"]=>
string(4) "nine"
["basisWeight"]=>
string(3) "ten"
["caliper"]=>
string(0) ""
["wetTensileStrenghtCD"]=>
string(0) ""
["wetTensileStrenghtMD"]=>
string(0) ""
["dryTensileStrengthCD"]=>
string(0) ""
["dryTensileStrengthMD"]=>
}
Post Reply