Problem with hidden input.[solved]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
MikeD
Posts: 294
Joined: Thu Sep 08, 2011 4:28 am

Problem with hidden input.[solved]

Post 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);
    
    }
Last edited by MikeD on Tue Jan 10, 2012 11:20 pm, edited 1 time in total.
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Problem with hidden input.

Post 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) 
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
MikeD
Posts: 294
Joined: Thu Sep 08, 2011 4:28 am

Re: Problem with hidden input.

Post 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 )
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Problem with hidden input.

Post by Chris »

From what I can see there shouldn't be anything wrong. What does the rest of the script look like?
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
MikeD
Posts: 294
Joined: Thu Sep 08, 2011 4:28 am

Re: Problem with hidden input.

Post 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>";
    }
}
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Problem with hidden input.

Post 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
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
MikeD
Posts: 294
Joined: Thu Sep 08, 2011 4:28 am

Re: Problem with hidden input.

Post 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!
Post Reply

Return to “Beginner Help and Support”