PHP - Weird Issue While Setting Object Parameters From $_post Array
There's probably an obvious reason but I can't seem to find it...
I start with the $_POST array, received from a form: Code: [Select] array(9) { ["Name"]=> string(3) "KTN" ["SQLServer"]=> string(24) "10.6.11.20\VSQLI028,1433" ["Username"]=> string(2) "GF" ["Password"]=> string(2) "GF" ["MasterDB"]=> string(11) "GFMaster_KN" ["Version"]=> string(3) "4.9" ["Prod"]=> string(1) "1" ["Monitored"]=> string(1) "0" ["button"]=> string(38) "updateColumnName=EnvironmentID;Value=1" } I get the button value from the array, and unset the button array value. Code: [Select] function load_POST($name) { //returns value and removes it from $_POST array. returns NULL if not existing. $debug = 0; if ( $debug == 1 ) { $backtrace = backtrace(); echo __FUNCTION__."()"; echo " <i>called by ".basename($backtrace[1]['file'])."</i><br/>\n"; } $post = NULL; if( array_key_exists($name, $_POST) ) { $post = urldecode($_POST[$name]); if ( $debug == 1 ) { echo "post $name, value: $post<br/>\n"; } } else { if ( $debug == 1 ) { echo "post $name: doesn't exist<br/>\n"; } } unset($_POST[$name]); return $post; } $_POST is now: Code: [Select] array(8) { ["Name"]=> string(3) "KTN" ["SQLServer"]=> string(24) "10.6.11.20\VSQLI028,1433" ["Username"]=> string(2) "GF" ["Password"]=> string(2) "GF" ["MasterDB"]=> string(11) "GFMaster_KN" ["Version"]=> string(3) "4.9" ["Prod"]=> string(1) "1" ["Monitored"]=> string(1) "0" } Then I create the object to assign the values to: Code: [Select] object(Environment)#1 (9) { ["EnvironmentID"]=> NULL ["Name"]=> NULL ["SQLServer"]=> NULL ["Username"]=> NULL ["Password"]=> NULL ["MasterDB"]=> NULL ["Version"]=> NULL ["Prod"]=> int(0) ["Monitored"]=> int(0) } So far so good Then, for each remaining $_POST value, I update the Object accordingly: First one, parametername: Name, parameter: KTN Code: [Select] object(Environment)#1 (10) { ["EnvironmentID"]=> NULL ["Name"]=> string(3) "KTN" ["SQLServer"]=> NULL ["Username"]=> NULL ["Password"]=> NULL ["MasterDB"]=> NULL ["Version"]=> NULL ["Prod"]=> int(0) ["Monitored"]=> int(0) ["ColumnName=EnvironmentID;Value=1"]=> object(stdClass)#3 (1) { ["ColumnName"]=> string(1) "1" } } And there we have the problem, for some reason the button value is added to the object somehow... Any ideas? Thanks in advance! Similar TutorialsI'm practicing my OOP skills and want to pass $_POST values to an Object's Instance Variables when a form is submitted. This is what I have so far... index.php Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> </head> <body> <!-- Registration Form --> <form method="post" action="results.php"> <!-- Registration Fields --> <div> <label for="email">E-mail:</label> <input type="text" name="email" class="txt" id="email" /> </div> <div> <label for="password">Password:</label> <input type="password" name="password" class="txt" id="password" /> </div> <div> <input type="submit" name="btnSubmit" value="Register" class="btn" id="btnSubmit" /> </div> </form> </body> </html> results.php Code: [Select] <?php include ('classes/FormHandler.class.php'); ?> FormHandler.class.php Code: [Select] <?php class HandleForm { // Define Variables. private $email; private $password; public function __construct($email, $password){ $this->email = $email; $this->password = $password; } } ?> I'm a little stuck on how I initialize the Instance Variables in the Constructor?! TomTees I have some function or method. Is there a better design patter to implement this?
function myFunction($a=null,$b=null,$c=null,$d=null,$e=null,$f=null,$g=null,$h=null) { //Do a bunch of stuff }Maybe the second function? function myNewFunction($data=array()) { $data=array_merge(array('a'=>null,'b'=>null,'c'=>null,'d'=>null,'e'=>null,'f'=>null,'g'=>null,'h'=>null),$array); //Do a bunch of stuff }Please provide decision making factors why you would use one approach over the other. Nonsense question, but still... Is there any method to detect gmail client timezone setting? Like mobile app and web gmail client? Not browser or IP or similar, but gmail. Thank you for your answers. Hello all, I'm kind of a noob to PHP, and as such have been teaching myself the language. I'm attempting to insert tag attributes in divs, based on whether the site is viewed in IE or Firefox, to account for subtle differences in appearance. The problem, however, is that the variable $boxorlink apparently has the value "box" the second time I call the method, even though I explicitly state "other" as the parameter; the else clause is never reached. If anybody could tell me why this is happening, please let me know. My entire HTML code is below... <html> <head> <style type ="text/css"> html { background-image:url('denim.jpg'); } .wrapper { min-width:600px; width:600px; height:800px; position:fixed; } .headertext { font-weight:bold; color:#FFFFFF; font-size:24pt; font-family:sans serif; text-shadow: 0.1em 0.1em #333 } .miniheadertext { font-weight:bold; color:#FFFFFF; font-size:16pt; font-family:sans serif; text-shadow: 0.1em 0.1em #333 } div.transbox { width:750px; height:180px; margin:30px 50px; border-style:solid; border-color:#c0c0c0; background-color:#000000; /* for IE */ filter:alpha(opacity=30); /* CSS3 standard */ opacity:0.3; } div.currentpagelink { width:90px; height:22px; margin:30px 50px; background-color:#c0c0c0; font-color:#FFFFFF; font-weight:bold; font-size:14pt; font-family:sans serif; text-align:center; /* for IE */ filter:alpha(opacity=40); /* CSS3 standard */ opacity:0.4; } } div.otherpagelinks { width:100px; height:50px; font-size:14pt; font-family:sans-serif; } </style> <title> Marvin Serrano's Online Portfolio </title> <?php function checkBrowser($boxorlink, $left, $top, $displaceleft, $displacetop) { //new positions for Firefox $newleft = $left + $displaceleft; $newtop = $top + $displacetop; //positions for links... $newlinkleft = $left - $displaceleft; $newlinktop = $top - $displacetop; //checks for box on top or links; links have to be certain % from top. if ($boxorlink = 'box') { if (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE') !== FALSE) { echo('left:'.$left.'%'); } else { echo('left:'.$newleft.'%'); } } elseif ($boxorlink = 'other') { if (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE') !== FALSE) { echo('left:'.$left.'%;'.'top:'.$top.'%'); } else { echo('left:'.$newlinkleft.'%;'.'top:'.$newlinktop.'%'); } } } ?> </head> <div class="wrapper"> <div class ="transbox" style="position:absolute; <?php checkBrowser('box',19,0,9,0) ?>"> <div class ="headertext" style="position:absolute; left:30%; top:30%">MARVIN SERRANO</div> <div class ="miniheadertext" style="position:absolute; left:29%; top:55%">Live for today, dream for tomorrow.</div> </div> <div class ="currentpagelink" style="position:absolute; <?php checkBrowser('other',38.1,26.3,10.1,3) ?>"> Home </div> <div class="otherpagelinks"> </div> </div> </html> -Marvin I need to set a deep property if it is undefined or NULL such as shown below: function setProperty($value, stdClass $config, $p1, $p2, $p3, $p4) { if(!isset($config->$p1->$p2->$p3->$p4) || is_null($config->$p1->$p2->$p3->$p4)) { $config->$p1->$p2->$p3->$p4=$value; } } $config=json_decode(json_encode(['a'=>['b'=>['c'=>['x'=>null, 'y'=>123]], 'x'=>123],'x'=>['x'=>123], 'x'=>123])); setProperty(321, $config, 'a','b','c','x'); setProperty(321, $config, 'a','b','c','y'); But I wish the function to work regardless of property depth and came up with the following. Recommendations for a cleaner way? Maybe I should be working with arrays and array_merge_recursive()? function setProperty($value, stdClass $config, array $properties) { $property=array_shift($properties); if(!count($properties)){ if(!isset($config->$property) || is_null($config->$property)) { $config->$property=$value; } } else { if(empty($config->$property) || !is_object($config->$property)) { $config->$property=new \stdClass(); } setProperty($value, $config->$property, $properties); } } $config=json_decode(json_encode(['a'=>['b'=>['c'=>['x'=>null, 'y'=>123]], 'x'=>123],'x'=>['x'=>123], 'x'=>123])); setProperty(321, $config, ['a','b','c','x']); setProperty(321, $config, ['a','b','c','y']);
I work with a large codebase and I have this situation come up fairly often:
the legacy class has large objects such as:
$design->motor->dimensions->a; $design->motor->dimensions->bd; $design->specifications->weight; $design->data->height; //etcWhen I create a new class, that class sometimes operates on the specific data, so say: class MyClass { public function compute($weight, $height, $a) { //stuff } } //and I call this for example as such: (new MyClass())->compute($design->specifications->weight, $design->data->height, $design->motor->dimensions->a);CONS: Potential issue: if design specs change and I need to change things parameters in "compute" function, I need to "re-key" the variables I pass to the function, and adjust things accordinly in MyClass as wel. PROS: only the exact data is being passed, and this data can come from anywhere it is viable, so in effect the function is fairly well separated, I think. Alternative option for me is to pass the entire design object, i.e class MyClass { public function compute(&$design) //can also be done via DI through a setter or constructor. { print $design->specifications->weight; print ($design->data->height + $design->motor->dimensions->a); //stuff } } (new MyClass())->compute($design);PROS: In this case when things change internally in which variables are needed and how things are computed, I only need to change the code in compute function of the class itself. CONS: MyClass now needs to be aware of how $design object is constructed. When it comes to this parameter passing, and Dependency Injection like this in general, does Computer Science advocate a preference on this issue? Do I pass the entire object, or do I pass only the bits and pieces I need? Hey guys, how are you. I have an odd problem and I am not sure what is causing it. I recently finished my form system, with PHP validation that sends the inputted information via email. Now, everything is working fine on my end with absolutely no issues, but it is not working on any other computers, even though my computer is in no way hosting the files. Now, the issue other computers are getting is when the form is filled out it doesn't redirect to the success page, it redirects back to the form page with nothing filled out and it doesn't display the errors on the page. Any idea on what might be causing this? Again, EVERYTHING works flawlessly on my end, that being, the display of any errors, the proper redirect, everything. Thanks!!! Is there an easy way to dump out the contents of a $_POST array and display them on my screen? (I'm trying to get more comfortable with what is stored in the $_POST array and how it is structured.) Thanks, TomTees I am trying to post while loop array. But I dont know how to do this and I used foreach and it works for each array but doesnt loop this. My table has Que_ID, Question, choice1, choice2, choice3 and choice 4. I would like to do something like.. For each Que_id (choice1, choice2, choice3 , choice4), this should be looped for each que_id so far I have Code: [Select] $counter = 1; while( $info = mysql_fetch_array( $sqll )) //)) { echo "{$info['Que_ID']} <br />\n"; echo "<input type='hidden' name=\"Que_ID\" value=\"{$info['Que_ID']}\" /> "; echo "{$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; $counter++; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; $counter++; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; $counter++; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; $counter++; How would go on to posting these while loop and display Que_ID and all the choices that are ticked for this que_ID and if its not ticked then its 0. How do I assign the entire $_POST array to a varible? This code isn't working... <?php echo 'FormHandler'; class FormHandler{ private $formValues = array(); $this->formValues = $_POST; } ?> TomTees Hi. First timer here. I'm trying to iterate through 5 arrays in a foreach loop. Yep, I know you'll say just use a counter that increments. Sadly, that gives me horrendous results! So, I am using the next & current methods of arrays. Thing is, it gives me bad results ( items that weren't even chosen on the next page ), or it leaves the first couple of items out. I did this : Code: [Select] <?php $ID = array(); $NAME = array(); $PRICE = array(); $QUANT = array(); $checkCount = 0; foreach (array_keys($_POST) as $key) { $$key = $_POST[$key]; $iPos = strpos($key, "ID"); $nPos = strpos($key, "NAME"); $pPos = strpos($key, "PRICE"); $qPos = strpos($key, "QUANT"); $cPos = strpos($key, "CHECK"); if ($iPos !== false) { $ID[] = $$key; } else { //echo "The string ID was not found in the string "; } if ($nPos !== false) { $NAME[] = $$key; } else { //echo "The string NAME was not found in the string "; } if ($pPos !== false) { $PRICE[] = $$key; } else { //echo "The string PRICE was not found in the string "; } if ($qPos !== false) { $QUANT[] = $$key; } else { //echo "The string QUANT was not found in the string "; } if ($cPos !== false) { $checkCount++; if ($checkCount == 1) { echo "Product ID <input type = 'text' name = 'ID" . current($ID) . "' value = '" . current($ID) . "'></br>"; echo "Product Name <input type = 'text' name = 'NAME" . current($NAME) . "' value = '" . current($NAME) . "'></br>"; echo "Product Price <input type = 'text' name = 'PRICE" . current($PRICE) . "' value = '" . current($PRICE) . "'></br>"; echo "Product Quantity <input type = 'text' name = 'QUANT" . current($QUANT) . "' value = '" . current($QUANT) . "'></br>"; } if ($checkCount > 1) { echo "Product ID <input type = 'text' name = 'ID" . next($ID) . "' value = '" . next($ID) . "'></br>"; echo "Product Name <input type = 'text' name = 'NAME" . next($NAME) . "' value = '" . next($NAME) . "'></br>"; echo "Product Price <input type = 'text' name = 'PRICE" . next($PRICE) . "' value = '" . next($PRICE) . "'></br>"; echo "Product Quantity <input type = 'text' name = 'QUANT" . next($QUANT) . "' value = '" . next($QUANT) . "'></br>"; } } else { //echo "The string CHECK was not found in the string "; } } ?> You will see I did all the processing under the CHECK if statement, the reason for this is, it is easier to identify the items ordered because they have been checked on the previous page. How do I post a for loop array in the next page. I am printing Question ID and choices for these and would like the for loop to print Question ID and choice that are checked for these. If the choice is ticked then it shoul return a 1 if the choice is empty then it should print 0. and I would like to insert this to a new table. How would I do this. Code: [Select] $intNum = 1; $intnumber = 1; while( $info = mysql_fetch_array( $sqll )){ echo "<input type='hidden' name=\"Que_ID\" value=\"{$info['Que_ID']}\" /> "; echo " $intNum, {$info['Que_Question']} <br />\n"; $intNum++; ?> <br> <?PHP for ($i =1; $i < 5; $i++) { echo "<input type=\"checkbox\" name=\"choice[{$intnumber}]\" />{$info['Que_Choice'.$i]}"; $intnumber++; } this is my form that print the question and it works fine. Code: [Select] <?PHP foreach ($_POST["Que_ID"] as $question) { $_POST["choice"] = $choice; echo "Question id: ".$question. $choice"<br />"; This is the post code but I know I need to do so much more but not sure how? Ayone help me or direct me to a source or tutorial or something. I usually hate to post something like this as a first post...I'd like to at least do an into but I"m stumped and I think it's a totally stupid thing I"m not noticing. Anyway, this is the final step in a three step user verification; this is for a staff user to be verified. Anyway, by now they have already verified their email and entered a random code so I"m only worried about actually setting them to verified status in my database so they can start working on blogs etc. Anyway, this form is supposed to find all unverified staff members, and allow an admin to easily just click down the list (one at a time currently) and verify the user (ie. setting their database status to verified_staffUser). The username that is supposed to be verified (or declined and therefore their entry deleted) is supposed to be passed through as $_POST[vnsupUsername]. This is set each time it loops through and prints a new user. The problem is that it's only sending the final username when I click verify/decline on any user :\. I"m not sure why it's doing this. In firebug on firefox it's showing that the user name is set for each one to be properly in the form...but when I click on it (I am having on my machine) the username being worked with echoed..and it's always the last one that was entered into the database. I have no idea why this is happening ..any thoughts? Code: [Select] <?php if(isset($_GET[vnsufac]) || isset($_POST[svnsu]) || isset($_POST[dvnsu])){ // simply prints the back home button echo "<form action=\"http://localhost/~atharp1122/OGirly_Site/ogirly_staff_homepage.php\" method=\"post\">" ."<input type=\"submit\" value=\"Back to Staff Homepage\" style=\"margin-top:10px;\">"; // this will print out the form to verify/deny all new staff user requests that have been email verified $programCheckUVStaff = mysql_query("SELECT username, email, firstname, lastname FROM staffUNAP where verified_staff = '0'"); while($UVStaff = mysql_fetch_assoc($programCheckUVStaff)){ print "<div class=\"newVerifyUserContain\" >"; print "<div class=\"newVerifyUser\" >"; echo "<h3 style=\"text-align: center;\">Would you like to verify this Staff request?</h3>"; echo "<table><tr><td>" ."<img src=\"images/default_icons/di_bunny_rabbit.png\" width=\"56\" height=\"59\" />" ."<ul style=\"padding-left: 100px; padding-bottom: 20px; margin-top: -42px; list-style-type: none;\"><li>" ."{$UVStaff[username]} aka {$UVStaff[firstname]} {$UVStaff[lastname]}</li><li>" ."{$UVStaff[email]}</li></ul></td></tr><tr><td>" ."<form action=\"{$_SERVER[PHP_SELF]}\" method=\"post\">" ."<input type=\"checkbox\" name=\"isadmin\" value=\"1\" style=\"margin-left: 10px;\">Is Admin?" ."<input type=\"hidden\" name=\"vnsupUsername\" value=\"{$UVStaff['username']}\">" ."<input type=\"submit\" name=\"svnsu\" value=\"Verify Staff\" style=\"margin-left: 200px;\">" ."<input type=\"submit\" name=\"dvnsu\" value=\"Decline Request\">"; print "</table>"; print "</div></div>"; } } // verify a staff member if(isset($_POST[svnsu])){ echo "verifying a new user"; echo $_POST[vnsupUsername]; } ?> I am calling CURL and trying to do a POST request with parameters: Code: [Select] $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Accept: application/json", "Content-Type: application/json")); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($curl, CURLOPT_USERAGENT, "curl 7.23.1 (x86_64-unknown-linux-gnu)"); curl_setopt($curl, CURLOPT_USERPWD, "username:password"); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_URL, "https://www.mydomain.com/route"); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, "key1=blah1&key2=blah2"); return curl_exec(curl); The problem, inside the request at http://www.mydomain.com/route I am not seeing any POST parameters passed. I.E. Code: [Select] print_r($_POST); Code: [Select] Array ( ) Should have key1=blah1 and key2=blah2. Any ideas? Well I have a script file that loads lots of info from a form using $_POST[] method, which is quite tedious: Code: [Select] $act = $_POST["act"]; $page = $_POST["page"]; $id = $_POST["id"]; $category = $_POST["category"]; $itemname = $_POST["itemname"]; $description = $_POST["description"]; $imageurl = $_POST["imageurl"]; $existingimageurl = $_POST["existingimageurl"]; $function = $_POST["function"]; $target = $_POST["target"]; $value = $_POST["value"]; $shop = $_POST["shop"]; $price = $_POST["price"]; $tradable = $_POST["tradable"]; $consumable = $_POST["consumable"]; I was wondering if there is a way to write one or two simple lines of code to load all variables stored in superglobal array $_POST[] efficiently. The point is to store all values within $_POST[] to an array called $item[], what I was thinking about is: Code: [Select] foreach($_POST = $key as $val){ $item['{$key}'] = $val; } Seems that its not gonna work, so I wonder if anyone of you have ideas on how I am able to simplify my code with 10-20 lines of $_POST[] to just 2-3 lines. Please do lemme know if this is possible, thanks. I need to email the form http://keegenk.com/providenceltddesign/ to myself. Right now, the email is sending and the confirmation page comes up, but the email does not have any of the data that should be collected by the form. I'll attach the php file that I'm using to capture the variable and send it to the email address. Any and all help is appreciated. Thanks a bunch I have a form that is populating fields based on a database query. I am then trying to update the database based on any changes made in the form and passed through a POST action. The problem I am having is with the block where I declare short variable names for the $_POST variables that will be passed when the user hits the submit button. For each variable declaration I get an error message like this: Quote Encountered error: 8 in mbr_profile_updt_form.php, line 130: Undefined index: email I have tried testing the $_POST variable using the isset function but it apparently is set but empty. What would be a good way to test to see if the user has pressed the submit button before I go into the processing block that is intended to handle those values from the form? Here is where my code is at right now: Code: [Select] if (!isset($_POST)) { throw new Exception('You have not filled the form out completely - please go back' .' and try again.'); } else { //filled in so create short variable names $email=$_POST['email']; $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; So ive created a forum that I got handling several different approvals. (it is used to approve or decline all submitted notes) it works fine and it even submits fine im at the part know where i process the information and do something with it, below is my form: <form action="course_proccess.php?action=approve" method="post"> <table align="left" border="1" cellspacing="0" cellpadding="3"> <tr> <td><b>Author</b></td> <td><b>File name</b></td> <td><b>Download</b></td> <td><b>Suggested catagory</b></td> <td><b>Select Catagory</b></td> <td>Approve</td> </tr> <td><input type="text " disabled="disabled" name="tr1_author" value="MikeH" </td> <td><input typee="text " disabled="disabled" name="tr1_name" value="A lot of my skills set back"</td> <td><a href= /uzEr%20Upl0ds/cache.zip > Download</a></td> <td>1001 Laws - Polceing </td> <td><select name="tr1_scatagory"> <option value="1"> Intro To Law </option> <option value="2"> 1001 Laws - Police Foundations </option> </select></td> <td><select name = "tr1_approve"> <option value = "1"> Yes</option> <option value = "2"> no</option> </select></td> </tr> <td><input type="text " disabled="disabled" name="tr2_author" value="MikeH" </td> <td><input typee="text " disabled="disabled" name="tr2_name" value="MM"</td> <td><a href= /uzEr%20Upl0ds/Michael Heintzman.doc > Download</a></td> <td>1001 Laws - Polceing </td> <td><select name="tr2_scatagory"> <option value="1"> Intro To Law </option> <option value="2"> 1001 Laws - Police Foundations </option> </select></td> <td><select name = "tr2_approve"> <option value = "1"> Yes</option> <option value = "2"> no</option> </select></td> </tr> <input type="hidden" name="rowCount" value="2"> <tr> <td><input type="submit" name="sendData" value="send"/></td> </tr> </table> </form> so what I do in my process file is I have a for loop for all of the "TR's" in the table and if it is approved I have an if statment and then I want to add db stuff my problem is my $_POST's are returning blank and I have no idea why. Can someone please assit me with this? (p.s i have debugged and it does get into the if approve == 1 statment. if(isset($_GET['action'])){ if ($_GET['action'] == "approve"){ if(isset($_POST['sendData'])) { $dataArray = array(); $row_count = $_POST['rowCount']; for($i=1;$i<$row_count;$i++) { $approven = "tr".$i."_approve"; $approve = $_POST[$approven]; if($approve == 1) { //Move the info over to "approved files" and delete it out of newnotes $author = "tr".$i."_author"; $location = "tr".$i."_location"; $catagory ="tr".$i."_scatagory"; $filename = "tr".$i."_name"; $submitedby = $_POST['author']; die($submitedby); $dataArray[]=array('author'=>$author,'fileName'=>$fileName,'Catagory'=>$catagory,'location'=>$location); var_dump($dataArray); }else{ //Email user saying they did not recive credits AND delete the entry } } if(!empty($dataArray)) { //now do what you want with the dataArray... var_dumb($dataArray); } } } 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 by Raz3rt, 20 May 2014 - 02:56 AM. Hi the above title explains it all.How to output a post array which has been given input using forms.I know you can do it my echo but what about print() Thanks |