phpretard Posted September 24, 2008 Share Posted September 24, 2008 I am trying to get the page title to read the value of $APCompany I can't get the value from the while loop into the function that displays the form... Please Help. <? $ID=$_GET['ID']; include ("connect.php"); $result = mysql_query("SELECT * FROM table WHERE ValKey='$ID'"); while($row = mysql_fetch_array($result)) { $APCompany=$row['APCompany']; $APEmail=$row['APEmail']; } //END WHILE echo $APCompany; <<<<<<<<<<<<< IT WILL DISPLAY HERE function VerifyForm(&$values, &$errors) { // VALLIDATION if ($_POST['pass']!=$_POST['pass2']) $errors['pass'] = "ERROR 1"; if (!$_POST['pass']) $errors['pass'] = "ERROR 2"; return (count($errors) == 0); } function DisplayForm($values, $errors) { ?> <html> <head> <title><? echo $APCompany; ?></title> <<<<<<<<<<<<<<<<<< HERE IS THE PROBLEM NO DISPLAY <style> TD.error { color: red; font-weight: bold; } </style> </head> <body> <div align="center"> <table> <form action="<?= $_SERVER['PHP_SELF'] ?>" method="POST"> <tr> <td colspan=2 height='30' style='padding-left:50px;'><?= $errors['pass'] ?><?= $errors['pass2'] ?></td> </tr> <tr> <td align=right>New Password:</td> <td><input class='input' type="text" size="30" name="pass" value="<?= htmlentities($values['pass']) ?>" autocomplete='off' /> </tr> <tr> <td>Confirm:</td> <td><input class='input' type="text" size="30" name="pass2" value="<?= htmlentities($values['pass2']) ?>" autocomplete='off'/> </tr> <tr><td colspan="2" align="center"><input class='select' type="submit" value="Submit"></tr> </form> </table> </div> </body> </html> <?php } function ProcessForm($values) { $TO = ""; $from = ""; $subject = ""; $body= ""; mail($TO, $subject, $body, "From: <$from>"); echo " <html> <head> <title>$APCompany</title> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<, AND AGAIN </head> <body> <div align='center'> <table bgcolor='#FFFFFF'> <tr> <td><center>SUCCESS</center> </td> </tr> </table> </div> </body> </html> "; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $formValues = $_POST; $formErrors = array(); if (!VerifyForm($formValues, $formErrors)) DisplayForm($formValues, $formErrors); else ProcessForm($formValues); } else DisplayForm(null, null); ?> <? mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 24, 2008 Share Posted September 24, 2008 functions have their own variable scope, meaning variables defined outside of the function can not be used within it (and vice-versa ) In order to use a variable from outside of the function, either pass it the function via a parameter, or use the global the keyword (not recommended). examples: function a($var) { echo $var; } $var = 'Hello'; a($var); // 'Hello'; // OR function b() { global $var; echo $var; } $var = 'Hello'; b(); // 'Hello'; Quote Link to comment Share on other sites More sharing options...
phpretard Posted September 24, 2008 Author Share Posted September 24, 2008 So this part of the code would be it's own function? $ID=$_GET['ID']; include ("connect.php"); $result = mysql_query("SELECT * FROM table WHERE ValKey='$ID'"); while($row = mysql_fetch_array($result)) { $APCompany=$row['APCompany']; $APEmail=$row['APEmail']; } //END WHILE Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 24, 2008 Share Posted September 24, 2008 No a function is defined using function function_name(/*... parameters here ...*/) { // code here } Quote Link to comment Share on other sites More sharing options...
phpretard Posted September 24, 2008 Author Share Posted September 24, 2008 With your example... function a($var) { echo $var; } $var = 'Hello'; a($var); // 'Hello'; function DisplayForm($values, $errors){ how do I echo "Hello" it in here } Quote Link to comment Share on other sites More sharing options...
.josh Posted September 24, 2008 Share Posted September 24, 2008 You need to pass $var to DisplayForm: function a($var) { echo $var; } $var = 'Hello'; a($var); // 'Hello'; function DisplayForm($values, $errors, $var){ a($var); } Quote Link to comment Share on other sites More sharing options...
phpretard Posted September 24, 2008 Author Share Posted September 24, 2008 Thank you!!! 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.