Jump to content

Code works in 4 but not in 5 ?


rgallant

Recommended Posts

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]<?php
function 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 alone
if ($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 red

if($_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>
<?php
if($_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 profile

if ($_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 row
echo "</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 row
echo "</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>
<?php
if($_SESSION['Oth_prod']==0)
{
echo "<p><input type='Checkbox' name='Oth_prod'> Would you like information about other products</p>";
}
?>
<?php
}
?>[/code]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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 helpful


Richard.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.