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
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>
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>
Copy link to clipboard
Copied
Yep - that did it - Thanks a lot.
Robert
Copy link to clipboard
Copied
You're welcome.
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.
Copy link to clipboard
Copied
Opps, my appologies. First time on the forum for me.
Regards,
Robert
Copy link to clipboard
Copied
No problems. Thanks for fixing it so quickly, and welcome to the forum.
Copy link to clipboard
Copied
Thank you David & Robert..
Robert, Welcome to the Adobe family!