Page 1 of 1

Problem with hidden input.[solved]

Posted: Tue Jan 10, 2012 8:53 pm
by MikeD
This has happened to me all day, and my marketplace would be much easier if I could get these hidden inputs working correctly.

Here's the input in that will not work. The value shows up correctly in view source, but when I try to redeem the item, it comes up as an undefined index. The variable $row[3] is part of a different while loop. (which is still going)

Code: Select all

echo "<input type='hidden' name='aucid' value='$row[3]' />";
Here's the form

Code: Select all

      echo "<form action='market.php' method='post'>";
      echo "<select name='charname'>";
      $chars="SELECT `charname` FROM `characters` WHERE `pid`='$pid'";
        if ($chars2=mysqli_query($db,$chars))
          {
           while($row1 = mysqli_fetch_row($chars2))
            {
              echo "<option value='$row1[0]'>$row1[0]</option>";
            }
          }
       echo "</select>";
       echo "<input type='hidden' name='aucid' value='$row[3]' />";
       echo "<input type='submit' name='redeem' value='Redeem' />";
       echo "</form>";
Here's the start of the redeem code...

Code: Select all

  if (isset($_POST['redeem']))
    {
      $aucid=(int)$_POST['aucid'];
      
      $aucinfo="SELECT `cbid`,`highbid`,`aucend`,`bought` FROM `playermarket` WHERE `aucid`='$aucid'";
      $aucinfo2=mysqli_query($db,$aucinfo) or die(mysqli_error($db));
      $aucinfo3=mysqli_fetch_array($aucinfo2);
    
    }

Re: Problem with hidden input.

Posted: Tue Jan 10, 2012 9:25 pm
by Chris
Undefined index means that the index or key does not exist in that array or object. Try do a print_r on $row to see if the index 3 had a value.

Code: Select all

print_r($row) 

Re: Problem with hidden input.

Posted: Tue Jan 10, 2012 10:23 pm
by MikeD
Chris wrote:Undefined index means that the index or key does not exist in that array or object. Try do a print_r on $row to see if the index 3 had a value.

Code: Select all

print_r($row) 
Yup, shows up exactly how it's supposed to.

Array ( [0] => Power Brass Knuckles [1] => gloves [2] => 100 [3] => 24 )

Re: Problem with hidden input.

Posted: Tue Jan 10, 2012 10:39 pm
by Chris
From what I can see there shouldn't be anything wrong. What does the rest of the script look like?

Re: Problem with hidden input.

Posted: Tue Jan 10, 2012 10:54 pm
by MikeD
Chris wrote:From what I can see there shouldn't be anything wrong. What does the rest of the script look like?
The error comes from this (undefined index aucid)
$aucid=(int)$_POST['aucid'];
here's the rest of the code...

Code: Select all

<?php

include_once 'connect.php';
require_once 'forum/SSI.php';

$player=$user_info['username'];
$playerinfo="SELECT `id_member` FROM `smf_members` WHERE `member_name`='$player'";
$playerinfo2=mysqli_query($db,$playerinfo) or die(mysqli_error($db));
$playerinfo3=mysqli_fetch_array($playerinfo2);
$pid=$playerinfo3['id_member'];
?>

<table>
<tr>
<th>Auction</th>
<th>Type</th>
<th>Winning Bid</th>
<th>Redeem</th>

<?php
$aucinfo="SELECT `auctionname`,`type`,`cbid`,`aucid` FROM `playermarket` WHERE `bought`='1' AND `highbidderid`='$pid'";
if ($aucinfo2=mysqli_query($db,$aucinfo))
{
  while ($row = mysqli_fetch_row($aucinfo2))
    {
      echo "<tr>";
      echo "<td>$row[0]</td>";
      echo "<td>$row[1]</td>";
      echo "<td>$row[2]</td>";
      echo "<td>";
      print_r($row); 
      echo "<form action='market.php' method='post'>";
      echo "<select name='charname'>";
      $chars="SELECT `charname` FROM `characters` WHERE `pid`='$pid'";
        if ($chars2=mysqli_query($db,$chars))
          {
           while($row1 = mysqli_fetch_row($chars2))
            {
              echo "<option value='$row1[0]'>$row1[0]</option>";
            }
          }
       echo "</select>";
       echo "<input type='hidden' name='aucid' value='$row[3]' />";
       echo "<input type='submit' name='redeem' value='Redeem' />";
       echo "</form>";
       echo "</tr>";
    }
}

Re: Problem with hidden input.

Posted: Tue Jan 10, 2012 11:14 pm
by Chris
Well unless $row1[0] is screwing up your HTML some way.. there shouldn't be anything wrong. Try do a print_r on $_POST

Re: Problem with hidden input.

Posted: Tue Jan 10, 2012 11:20 pm
by MikeD
Chris wrote:Well unless $row1[0] is screwing up your HTML some way.. there shouldn't be anything wrong. Try do a print_r on $_POST
Just randomly started working, didn't change anything... :oops:

Thanks for the help though!