Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

<input type="hidden" name="h_id" value="$h_id"> will not work (at least for me...)

Community Beginner ,
Sep 19, 2012 Sep 19, 2012

Copy link to clipboard

Copied

Hi all - In my add new record form I have a hidden text field that I'm trying to use to insert a value into my database. This numeric value is contained in the variable $h_id which came from a $SESSION variable. I checked and it exists. The error I get from MySQL on submit is telling me that I'm trying to save a text value into a number field. That means the value in the hidden field is not saving as a number but as text 'h_id' instead of the value of 1.  Any idea of what I'm doing wrong here? I thought you could use variables in a hidden field.

This is the hidden field code:

<input type="hidden" name="h_id" value="$h_id">

Here is the MySQL error:

Cannot add or update a child row: a foreign key constraint fails (`outercircledb`.`cof_detail`, CONSTRAINT `FK_cof_detail` FOREIGN KEY (`h_id`) REFERENCES `cof_header` (`h_id`))

Regards,

Robert

TOPICS
Server side applications

Views

3.2K
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 19, 2012 Sep 19, 2012

You should echo your value field. PHP cannot retrieve ID fields 'as is'.

Your code should be like this:

<?php
if(array_key_exists('h_id', $_GET)) {
     $id
= (int) $_GET['h_id'];
}
?>

<form method="get" action="yourpage.php">
     <input type="hidden" name="h_id" value="
<?php echo $id; ?>">
    
<input type="button">
</form>


Votes

Translate
LEGEND ,
Sep 19, 2012 Sep 19, 2012

Copy link to clipboard

Copied

You should echo your value field. PHP cannot retrieve ID fields 'as is'.

Your code should be like this:

<?php
if(array_key_exists('h_id', $_GET)) {
     $id
= (int) $_GET['h_id'];
}
?>

<form method="get" action="yourpage.php">
     <input type="hidden" name="h_id" value="
<?php echo $id; ?>">
    
<input type="button">
</form>


Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 19, 2012 Sep 19, 2012

Copy link to clipboard

Copied

Yep - that did it - Thanks a lot.

Robert

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 19, 2012 Sep 19, 2012

Copy link to clipboard

Copied

You're welcome.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 19, 2012 Sep 19, 2012

Copy link to clipboard

Copied

When someone answers your question correctly, as Sudarshan has just done, please mark it as correct. It not only gives the other person points, but signals to everyone that the problem has been solved and makes it easier for others to find the solution to similar problems.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 19, 2012 Sep 19, 2012

Copy link to clipboard

Copied

Opps, my appologies. First time on the forum for me.

Regards,

Robert

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 19, 2012 Sep 19, 2012

Copy link to clipboard

Copied

No problems. Thanks for fixing it so quickly, and welcome to the forum.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 19, 2012 Sep 19, 2012

Copy link to clipboard

Copied

LATEST

Thank you David & Robert..

Robert, Welcome to the Adobe family!

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines