Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi all,
As the topic title suggests I'm trying to populate a hidden form element with a number retrieved from a DB query. The hidden field appears in the post array but with no value. Yet the value appears in the debugging info.
 
This is the query (it only returns one row):

$q = "SELECT H_H_allowance FROM curtain_constants";

$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));

if (mysqli_num_rows($r) == 0)
{
	//If there's nothing in the DB display this message
	echo '<p>Oops, something\'s gone wrong. We\'re working on it, please would you try again later. Apologies.</p>';	
}
else
{		
	$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
}

This is the hidden form field:

<input name="H_H_allowance" type="hidden" value="<?php $row['H_H_allowance'] ?>" />

This is the relevant debugging info:

[_POST] => Array        (            [fabric_width] => 139            [track_pole] =>             [drop] =>             [fullness] => 2            [vert_pattern_repeat] => 0            [hor_pattern_repeat] => 0            [pattern_match] => no            [H_H_allowance] =>             [submitted_curtains] => TRUE            [submit] => Get fabric quantity        )
[row] => Array        (            [H_H_allowance] => 25.00        )

Thanks once again.

Paul

 

Share this post


Link to post
Share on other sites

Load the form, and in your browser's element inspector, check out the hidden field. See if the expected value is there.

If it isn't, then something is probably wrong with retrieving your DB query.

Share this post


Link to post
Share on other sites

Hiya,

The hidden field is there.

 

My confusion is that if there was a problem with the DB query then $row would not contain 25.00. If there was a problem with the form element then the $_POST  array would not contain H_H_allowance. One just doesn't seem to pick up the other.

 

I've even just checked my spelling of allowance....make sure I didn't put allowence anywhere. Spelling is not my strong point, nor is PHP it appears!

 

One of those days today.

 

Cheers

Paul

Share this post


Link to post
Share on other sites

So, what's the deal? Is the DB query okay? Is the value in the markup before submitting the form? Is the hidden element actually within the form tags? Please provide more info.

Share this post


Link to post
Share on other sites

You haven't echo'ed the value:

<?php $row['H_H_allowance'] ?>

You need to use echo or print there. 

 

You can confirm this, by the way, by looking at the HTML source of the page.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...