Jump to content
Larry Ullman's Book Forums

Populating Hidden Form Fields From A Db Query

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>';	
	$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.



Link to comment
Share on other sites


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.




Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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.


  • Create New...