homepage Welcome to WebmasterWorld Guest from 54.205.254.108
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
POST variables inconsistent
Orangutang




msg:4260132
 11:58 am on Jan 30, 2011 (gmt 0)

Hi,

I've got a strange one here, usually when something doesn't work it always doesn't work so I can try breaking it down to have a look but here it only doesn't work with one scenario.

The code below displays 2 rows which are retrieved from the sql db via the initial page selection query. And heres where it goes strange.

First Scenario
2 rows are displayed
I input into the top row and the UPDATE statement doesn't work and the variables are not echoed to screen. But if I carry on and input into the second row it does work.

Second Scenario
2 rows are displayed
I input into the second row first and everything works and I carry on and input into the first row and everything works.

So the problem is only when I try the top row first as in first scenario?

I've put this issue into the test script below:

<?php
// connect to db

// posted varaiables
$gdsinno = $_POST['gdsinno'];
$suppref = $_POST['suppref'];
$gdsinreason = $_POST['gdsinreason'];

// PROBLEM does'nt work first time but does second?
if ($_POST['authbox']) {
$auth_array = isset($_POST['authbox']) && is_array($_POST['authbox'])? $_POST['authbox']: array();
foreach($auth_array as $reqid => $key) {
$gdquery = "UPDATE gdsin SET gdsinno = '$gdsinno', gireason = '$gdsinreason', suppref = '$suppref' WHERE reqid = '$reqid'";
$gdresult = mysql_query ($gdquery) or die (mysql_error());
}
}
?>

<hr>
<font color='#000'><?php
// For debugging
echo $reqid; echo $username; echo $gdsinno; echo $suppref; echo $gdsinreason; ?>
</font>
<form method="POST" action="postupdate.php">

<?php
// initial page selection
$firstquery = "SELECT * FROM `gdsin` WHERE `username` = 'test' AND `gdsinstatus` = 'expected' ";
$first = mysql_query($firstquery) or die(mysql_error());
while ($row = mysql_fetch_row($first)) {
$gdsinid = $row[0]; $reqid = $row[1]; $gdsinno = $row[7]; $gdsinreason = $row[8]; $suppref = $row[9];
?>
<font color="#blue">Req ID:<?php echo $reqid;?></font>
Gds In<input type ='text' class='input' size='18' name='gdsinno' value=''>
Supp Ref<input type ='text' class='input' size='18' name='suppref' value=''>
GD Reason<input type ='text' class='input' size='80' name='gdsinreason' value=''>
<input type="submit" class="buttonauth" name="authbox[<?php echo $reqid; ?>]" value="Submit">
<br>
<?php }; ?>
</form>

Any help would be much appreciated.

 

Orangutang




msg:4260161
 2:32 pm on Jan 30, 2011 (gmt 0)

In case it helps anyone, found out what it was. All I had to change was to put the closing form tag inside the while loop.

This:
<input type="submit" class="buttonauth" name="authbox[<?php echo $reqid; ?>]" value="Submit">
<br>
<?php }; ?>
</form>


To this:
<input type="submit" class="buttonauth" name="authbox[<?php echo $reqid; ?>]" value="Submit">
<br>
</form>
<?php }; ?>


Makes sense now I've found it but as they say "Its easy when you know how" :-)

rocknbil




msg:4260275
 9:12 pm on Jan 30, 2011 (gmt 0)

Right, and if you want a single form you would need to rename these. You'd be submitting two items with the same name in post

<input type ='text' class='input' size='18' name='gdsinno' value=''>

So you could add a counter and do gdsinno_1, gds_inno2, etc., or continue as you were and read them as an array.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved