Raz3rt Posted May 20, 2014 Share Posted May 20, 2014 (edited) Hi, i'm new here and hope i've finally found a forum where i can find the perfect solution for my questions. Well since a year now i started to work with PHP and still now and then there are some things where i seize on. My question is on of those situations. I have the following code: if (isset($_POST)){ foreach ($_POST as $key => $value){ if (!empty($value)){ $update_rma_detail_stmt = $dbh->prepare("UPDATE rma_detail SET $key = ? WHERE rd_rma_nr = ?"); $update_rma_detail_stmt->bindParam(1, $value); $update_rma_detail_stmt->bindParam(2, $getadmrmaid); $update_rma_detail_stmt->execute(); } } } All i want is when there is an empty (not filled in) input field because it is not mandatory the foreach still continuous to the end. When i use if (!empty($value)){ It still outputs these error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1366 Incorrect integer value: ' ' However, when i dont use i got an other error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value: '' It is however so that the datetime is the very first empty field it come across when looping. I think my if (!empty($value)){ is doing the right thing but still gives error's on integers. Can it be? I allready tried to use trim() or array_filter() but because i previously never used it i dont know if i am doing it the right way so any help is welkom! Thanks! Edited May 20, 2014 by Raz3rt Quote Link to comment Share on other sites More sharing options...
IanA Posted May 20, 2014 Share Posted May 20, 2014 So the value of key is going to be an integer value, right? I believe for PDO you should be specifying the data type, in this instance PDO::PARAM_INT: $update_rma_detail_stmt->bindParam(1, $value, PDO::PARAM_INT); Does this make any difference? The check for empty is returning FALSE so the variable must be a non-null value? Quote Link to comment Share on other sites More sharing options...
Solution Raz3rt Posted May 20, 2014 Author Solution Share Posted May 20, 2014 (edited) So the value of key is going to be an integer value, right? I believe for PDO you should be specifying the data type, in this instance PDO::PARAM_INT: $update_rma_detail_stmt->bindParam(1, $value, PDO::PARAM_INT); Does this make any difference? The check for empty is returning FALSE so the variable must be a non-null value? Thanks IanA for you reply! As i remember it is not nessesary to specify the date type, i never did it before though. After a long search i've manage to find my "stupid" fold i have made. My problem only appears when the foreach wanted to loop through a select from my form & my first rule in the select was: <option value="$nbsp;" selected></option>. As you may notice the value is a space so the person cannot make a wrong entry. Changing the to 0 fixed the problem. Sorry i had to bother for such a small thing. Edited May 20, 2014 by Raz3rt Quote Link to comment Share on other sites More sharing options...
IanA Posted May 20, 2014 Share Posted May 20, 2014 Glad your issue is resolved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.