PHP - Moved: Simple Function Problem
This topic has been moved to PHP Applications.
http://www.phpfreaks.com/forums/index.php?topic=344481.0 Similar TutorialsThis topic has been moved to Apache HTTP Server. http://www.phpfreaks.com/forums/index.php?topic=322454.0 Ok people I'm trying to write a simple function that will pass a blank string back to my form when the clear button is clicked, but for some reason it will not clear my form. I can't figure this out I have written other functions that have worked, but for some reason this has me stumped. Here is my function Code: [Select] //function to clear variables function clearVars(&$j, &$k) { $workValue = ""; $workType = ""; } Code: [Select] $workValue = (isset($_POST['vfld']))?$_POST['vfld']:''; $workType = (isset($_POST['tfld']))?$_POST['tfld']:''; if (isset($_POST['submit'])) { if ($_POST['submit'] == "Clear") { clearVars($vfld,$tfld); } elseif ($_POST['submit'] == "Calculate") { getVars($vfld,$tfld,$calc); $continue = testVars(); if ($continue == "yes") { switch ($workType) { case "circle": calcCircle($workValue); break; case "square": calcSquare($workValue); break; case "triangle": calcTriangle($workValue); break; } } } } ?> <form method="post" action="hw06.php" id="form1" name="form1"> <p> Enter a number here : <input type="text" id="vfld" name="vfld" value="<?php echo $workValue; ?>"/> </p> <p> This number is: <br /> <input type="radio" name="tfld" value="circle" <?php if ($workType == "circle") { echo 'checked="checked"'; } ?> /> : the radius of a circle <br /> <input type="radio" name="tfld" value="square" <?php if ($workType == "square") { echo 'checked="checked"'; } ?> /> : the length of one side of a square <br /> <input type="radio" name="tfld" value="triangle" <?php if ($workType == "triangle") { echo 'checked="checked"'; } ?> /> : the length of one side of an equilateral triangle </p> <p> <input type="submit" name="submit" value="Calculate" /> <input type="submit" name="submit" value="Clear" /> </p> </form> <div id="footer"> <pre>This page written by: <cite>The President</cite> ©2011 and beyond</pre> </div> </body> </html> Hello I am trying to create a simple update function. but it is giving me syntax error. May you please review my code The function call: function update_article_stats ($article_num) The Function Declaration in the functions.php function update_article_stats ($article_num) { $query = "UPDATE `articles_content` SET `cnt` = cnt+1 WHERE `num` = '$article_num' "; $result = mysql_query($query); } Thank you so much This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=349116.0 This topic has been moved to PHP Math Help. http://www.phpfreaks.com/forums/index.php?topic=357542.0 Code: [Select] function display_details($name, $department="sales", $sex="male") { return "You are {$name} from {$department} and you are {$sex}"; } I need to use the default value for $department, but none of the below work. How do I do it? echo $display_details("Sally", NULL, "female"); // sets $department as empty/blank echo $display_details("Sally", "", "female"); // sets $department as empty/blank echo $display_details("Sally", , "female"); // PHP error Ok so its been a while since school and ive forgotton most my php as Ive been more into site building wiht css, html and graphics... <?php $part=part(""); $size=size(""); $qty=qty(""); if (($part=="2") && ($size=="11") && ($qty=="100")) echo "Price quote is $59.00" else if (($part=="2") && ($size=="11") && ($qty=="500")) echo "Price quote is $99.00" ?> my goal is to have a simple form, wiht 3 drop downs qty, size, part are the field names. And depending what options they pick they get a price out put... im missing something so simple, I know it should only take a couple lines of code and simply repeat it wiht else if until you hit the end of all possible options. Can some one please help? Thanks This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=321641.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=314391.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=353729.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=350117.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=322930.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=333590.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=334308.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=329660.0 This topic has been moved to Other Programming Languages. http://www.phpfreaks.com/forums/index.php?topic=354391.0 This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=347660.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=355809.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=348759.0 but never on the first call. Okay, I posted this on StackOverflow but no one there seems to have an answer either. I have this simple function: Code: [Select] public function delete($messageID) { $type = $this->findType($messageID); if ($type == 'in') { foreach ($this->inArr as $key => $value) { if ($this->inArr[$key]->messageID != $messageID) $implodeData[$key] = $this->inArr[$key]->messageID; } if (!isset($implodeData)) $imploded = '0'; else $imploded = implode(',', $implodeData); $result = $this->_database->updatePMUser('inArr', $imploded, 'UID', $this->UID); $result2 = $this->_database->deletePM('messageID', $messageID); return; } else { foreach ($this->sentArr as $key => $value) { if ($this->sentArr[$key]->messageID != $messageID) $implodeData[$key] = $this->sentArr[$key]->messageID; } if (!isset($implodeData)) $imploded = '0'; else $imploded = implode(',', $implodeData); $result = $this->_database->updatePMUser('sentArr', $imploded, 'UID', $this->UID); $result2 = $this->_database->deletePM('messageID', $messageID); return; } } It is a delete function for a private messaging program for a forum script I'm writing. Anyway, here's the issue - it works! But only sometimes. It is called in 3 different places, always from a form processing class I have, once in the view message section to delete a message you're viewing, in a foreach from the sentbox options section and then a foreach in the inbox options section. The inbox and sentbox option sections do that whole "delete the checked messages" for the mass removal functionality. The delete function above works in all ways shapes and forms when I use it in single calls - like when I'm deleting a message while viewing it or when I only check one message from the inbox, etc - but when I call it multiple times (as in I have checked multiple messages) - it fully deletes one (both the message and the reference to the message in the user's db row) and then only deletes the actual message on the others (deleting the message is the call to deletePM - deleting the reference is the call to updatePMUser). Okay, if you need further information - the function above checks the type the message is (in the inbox or in the sentbox) and then uses that to foreach through that array (inArr or sentArr) of the user. It logs in all the messageIDs of the those that DON'T match the one we're deleting and then at the end it implodes those caught IDs into a string that is then updated in the user's row as a comma separated string of values each representing a message in the DB - you get the picture. I realize I have some trimming to do (for one I can cut the above function down by about half by using variable variables) but I'll get to that after I get the thing working. I can't figure out why it's doing what it's doing. If you need the function that calls this in the foreach, I have it below. Oh, and the thing that really boggles me is that this function is called fully for each checked message in the foreach - it fully returns and then loops - if it works once, I don't see how it wouldn't work on a second call from a loop - the variables it uses should be trashed when it leaves the function, they aren't global or object properties or anything. Color me confused. Thanks for any help, oh, here's one of the functions that calls it to delete checked messages (this one is for the sentbox, there is another for the inbox): Code: [Select] private function _processSelectedSent() { $pmObj = unserialize(base64_decode($_POST['pmObj'])); $i=1; foreach ($_POST as $key => $value) { if ($value == 'marked') { $checkedArray[$i] = $key; $i++; } } if ($_POST['submitter'] == 'Delete Selected') { if (is_array($checkedArray)) { foreach ($checkedArray as $key => $value) $pmObj->delete($value); } else $pmObj->delete($checkedArray[1]); header("Location: ".HOME_PAGE.PM_PAGE."?view=sentbox&nocache=".time()); } } |