Hi All, i’ve run into an issue and i cant see the wood through the trees.
The tables in question are the contacts & company table. The contact form is what i’m currently working on where staff can add new customers and assign them to a company. The company id (compid) is a foreign key that links the contacts table to the companies table. The odd thing is, its pulling the data from the companies table but wont submit the form as it’s giving me an incorrect integer value. However in the value box, i have echo’d the id of the company.
Please can someone tell me what i’m missing. Thanks in advance.
Does everything look OK in the resulting HTML?
Are the values in the options all integers as expected?
I’m not sure about having a value on the select though.
The sumbitted data doesn’t go anywhere. I get an error 500 and this…
PHP Fatal error: Uncaught mysqli_sql_exception: Incorrect integer value: ‘’ for column ‘compid’ at row 1 in …/z_createcontact.php:76
Stack trace: #0 …/z_createcontact.php(76): mysqli_stmt_execute(Object(mysqli_stmt)) #1 {main}
thrown in …/z_createcontact.php on line 76
Thats the name of the page that creates a contact and is what the above extract is from. The thing that i don’t understand is that its pulling the ID & company name from the company table, so in theory having inside the option it should post the id related to the company to the contacts table?
Which is what we’ve been asking you to post
Your bindparams say $param_compid is a string. Mysql is expecting it to be an integer. So it’s failing.
mysqli_stmt_bind_param($stmt, “sssssssss”, $param_compid, $param_fname, $param_lname, $param_title, $param_email, $param_contactno, $param_mobileno, $param_role, $param_status);
I… think so. I’m not 100% sure if the binding will take care of the String → Integer conversion for you or if you need to explicitly convert it when you say $param_compid = $compid.
Try it. If it fails, try explicitly converting your string to an integer, and try again.
The value should be that of the company id from which it came from (if that makes sense).
Apologies Sam i must have missed your comment.
Interesting point though. I’ll drop out the value to see if that stops throwing it off.
echo the value out so you can see what the script thinks it’s getting. That way you can figure out if it’s a problem in your conversion to integer, or the form’s just not sending the right value.