Paul Posted May 16, 2014 Share Posted May 16, 2014 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 Link to comment Share on other sites More sharing options...
HartleySan Posted May 16, 2014 Share Posted May 16, 2014 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. Link to comment Share on other sites More sharing options...
Paul Posted May 16, 2014 Author Share Posted May 16, 2014 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 Link to comment Share on other sites More sharing options...
HartleySan Posted May 16, 2014 Share Posted May 16, 2014 So you solved the problem then? Link to comment Share on other sites More sharing options...
Paul Posted May 16, 2014 Author Share Posted May 16, 2014 No, sorry. Just reread my post. That's what it sounds like but no. Paul Link to comment Share on other sites More sharing options...
HartleySan Posted May 16, 2014 Share Posted May 16, 2014 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. Link to comment Share on other sites More sharing options...
Larry Posted May 17, 2014 Share Posted May 17, 2014 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. Link to comment Share on other sites More sharing options...
HartleySan Posted May 17, 2014 Share Posted May 17, 2014 Good eye, Larry. I didn't even notice that. Thanks. Link to comment Share on other sites More sharing options...
Larry Posted May 18, 2014 Share Posted May 18, 2014 Well...it's a mistake I've made before! Link to comment Share on other sites More sharing options...
Recommended Posts