rgallant Posted July 22, 2006 Share Posted July 22, 2006 I have a small set of code that mixes php and html in the same function. It works on my test server apache and php 4.3.10 but not on an iis server and php 5.1.2. I am not by any means an expert at PHP but I can not see any good reason this should not work.This code is is included into a prior module via a require_once statement, script processing stops dead when it hits that require_once statement. I have done some quick testing to make sure this is where the fault is. Ihave a number of these with more to come so resolving this would be handy.Here is the code:[code]<?phpfunction de_layout($from)session_start();{// 1st check what script called us// INITAL or ERROR// if INITAL set all the session variables to 0 otherwise leave tham aloneif ($from == "INITAL"){// set all session variables we use to be zero$_SESSION['first'] = 0;$_SESSION['last'] = 0;$_SESSION['date'] = 0;$_SESSION['vendor'] = 0;$_SESSION['product'] = 0;$_SESSION['quantity'] = 0;$_SESSION['email'] = 0;}else{// get values that have been entered for display$first=$_SESSION['$first'];$last=$_SESSION['$last'];$Date=$_SESSION['$Date'];$vendor=$_SESSION['$Vendor'];$product=$_SESSION['$product'];$quantity=$_SESSION['$quantity'];$email=$_SESSION['$email'];$address1 = $_SESSION['$address1'];$address2=$_SESSION['$address2'];$city=$_SESSION['$city'];$postal = $_SESSION['$postal'];$country =$_SESSION['$Country'];$prov=$_SESSION['$Prov'];$alt_phone=$_SESSION['$alt_phone'];$alt_email=$_SESSION['$alt_email'];$sales_rep=$_SESSION['$sales_rep'];}// we will highlight all the incorrect entries in redif($_SESSION['first'] == 1){$style="style3";}else {$style = "style1";}echo "<td width><p class=$style>*First Name:</td><td width> <input type='text' name='first' value ='" .$first. "'></p></td>";if($_SESSION['last'] == 1){$style="style3";}else {$style = "style1";}echo "<td width><p class=$style>*Last Name:</td><td> <input type='text' name='last' value ='" .$last."'></p></td>";echo "<tr><td><p class='style1'>Street Address:</td><td><input type='text' name='address1' value ='".$address1."'></p></td><td><p class='style1'>Street Address2:</td><td><input type='text' name='address2' value = '".$address2."'></p></td></tr>";echo "<tr><td><p class='style1'>City:</td><td><input type='text' name='city' value ='". $city."'></p></td><td><p class='style1'>Postal Code:</td><td> <input type='text' name='postal' value ='". $postal."'></p></td></tr>";echo "<tr><td><p class='style1'>Country:</td><td></td><td>Prov:</td></tr>"; echo "<tr><td>"; // Query the countries table and load all of the records // into an array. $sql = 'SELECT * FROM countries'; $res = mysql_query($sql) or die(mysql_error()); while ($rec = mysql_fetch_assoc($res)) $countries[] = $rec; // die('<pre>'.print_r($countries)); echo '<SELECT name="Countries">'; foreach ($countries as $c) echo "<OPTION>{$c['Country']}</OPTION>\n"; echo '</SELECT>';?></td><td><input type="text" name="Country"></td><td><?php // Query the Province table and load all of the records // into an array. $sql = 'SELECT * FROM provinces'; $res = mysql_query($sql) or die(mysql_error()); while ($rec = mysql_fetch_assoc($res)) $provinces[] = $rec; // die('<pre>'.print_r($countries)); echo '<SELECT name="Provinces">'; foreach ($provinces as $p) echo "<OPTION>{$p['Province']}</OPTION>\n"; echo '</SELECT>';?></td><td><input type="text" name="prov"></td></tr><?phpif($_SESSION['email'] == 1){$style="style3";}else {$style = "style1";}echo "<tr><td><p class=$style>*E-mail:</td><td> <input type='text' name='email' value ='". $email."'></p></td>";// optional fields to be controled by a profileif ($_SESSION['alt_email']==0){echo "<td><p class=$style>Alt E-mail:</td><td> <input type='text' name='alt_email' value ='". $alt_email."'></p></td></tr>";}else{// end the rowecho "</tr>";}if ($_SESSION['phone']==0){echo "<tr><td><p class=$style>Phone Number:</td><td> <input type='text' name='phone' value ='". $phone."'></p></td>";}if ($_SESSION['alt_phone']==0){ if ($_SESSION['phone']==0) { echo "<td><p class=$style>Alt Phone Number:</td><td> <input type='text' name='alt_phone' value ='". $alt_phone."'></p></td></tr>"; } else { echo "<tr><td><p class=$style>Alt Phone Number:</td><td> <input type='text' name='alt_phone' value ='". $alt_phone."'></p></td></tr>"; }}else{// end the rowecho "</tr>";}if($_SESSION['vendor'] == 1){$style="style3";}else {$style = "style1";}echo "<tr><td><p class=$style>*Purchased From:</td><td>"; // Query the Vendor table and load all of the records // into an array. $sql = 'SELECT * FROM vendors'; $res = mysql_query($sql) or die(mysql_error()); while ($rec = mysql_fetch_assoc($res)) $vendors[] = $rec; // die('<pre>'.print_r($countries)); echo '<SELECT name="Vendors">'; foreach ($vendors as $v) echo "<OPTION>{$v['Vendorname']}</OPTION>\n"; echo '</SELECT>'; echo"</p></td>";if($_SESSION['date'] == 1){$style="style3";}else {$style = "style1";}echo "<td><p class=$style>*Purchase date:</td><td> <input type='text' name='date' value ='".$Date."'></td><td> Year- month - day</p></td></tr>";if($_SESSION['product'] == 1){$style="style3";}else {$style = "style1";}echo "<tr><td><p class=$style>*Product Purchased:</td><td>"; // Query the Product table and load all of the records // into an array. $sql = 'SELECT * FROM Products'; $res = mysql_query($sql) or die(mysql_error()); while ($rec = mysql_fetch_assoc($res)) $products[] = $rec; // die('<pre>'.print_r($countries)); echo '<SELECT name="Products">'; foreach ($products as $P) echo "<OPTION>{$P['Product']}</OPTION>\n"; echo '</SELECT>';echo "</p></td>";if($_SESSION['quantity'] == 1){$style="style3";}else {$style = "style1";}echo "<td><p class=$style>*Quantity Purchased:</td><td> <input type='text' name='Quantity' value = '".$quantity."'></p></td></tr>";if ($_SESSION['sale_rep']==0){echo "<tr><td><p class=$style>Sales Rep:</td><td> <input type='text' name='sale_rep' value ='". $sale_rep."'></p></td></tr>";}?><tr></tr></table><p><input type="Checkbox" name="update_news"> Would you like to have product information e-mailed to you </p><p><input type="Checkbox" name="ver_email"> Would you like to have your registration information e-mailed to the email address provided</p><?phpif($_SESSION['Oth_prod']==0){ echo "<p><input type='Checkbox' name='Oth_prod'> Would you like information about other products</p>";}?><?php}?>[/code] Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 22, 2006 Share Posted July 22, 2006 [quote]script processing stops dead when it hits that require_once statement[/quote]And what error message do you see (if any). Is there any active error trapping and/or error display? Quote Link to comment Share on other sites More sharing options...
rgallant Posted July 23, 2006 Author Share Posted July 23, 2006 No errors, the script simply stops. I have 3 includes this is the last one, right after this it should call the routine to diplay the page header and footer. The script ends, I have placed echo statements and I never get the one after the call to the code above. If I comment out the require_once for this code all is good.But that is a good point I will add an error trap to both the calling program and this one.I also tried converting the remaining html into echo statements, hoping I had messed up the script end and start tags, no joy there either.Correct me if I am wrong but I thought the Require_once simply included the code, and should not cause an error unless the included code does not exist. Quote Link to comment Share on other sites More sharing options...
Branden Wagner Posted July 23, 2006 Share Posted July 23, 2006 I had a problem once before where for loops wouldnt work in 5 but they would in 4, i reinstalled 5 and that fixed the problem... i dont know if thats of any help.. but its just a suggestions. Quote Link to comment Share on other sites More sharing options...
rgallant Posted July 23, 2006 Author Share Posted July 23, 2006 Hi all thanks for the suggestions,The last one about the IF statements had me go over the code chunk by chunk.What I have found is the various PHP settings on the IIS server are more restrictive. By enabling error messages a number of things that passed on the 4.3 server will not work on the 5 and IIS. Oh well live and learn. I just need to go over all of the code step by step and clean up the problems. From here on in I will be much more careful about my coding.On another note I found these forums very usefull, and the replies genuinely helpfulRichard. 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.