Jump to content

[SOLVED] header issue


thedevilz

Recommended Posts

Dear all,

 

There is my code, I am not sending any thing to the browser except the form and trying to call header function but it gives me error.

Want your kind help

 

<html>

<head>

<title>Order Online</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">

<!--

.style1 {

font-family: Arial, Helvetica, sans-serif;

font-weight: bold;

}

-->

</style>

</head>

 

<body>

<?php

//$page_title = 'Order Online';

require_once('../connect.php');

ob_start();

if (isset($_POST['submitted']))

{

$trimmed = array_map('trim',$_POST);

$fn = $ln = $e = $q = FALSE;

$cdb=new class_mysql;

if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['f_name']))

{

$fn = $trimmed['f_name'];

}

else

{

echo '<p><span class=style1>Please enter your first name!</span></p>';

}

if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['l_name']))

{

$ln = $trimmed['l_name'];

}

else

{

echo '<p><span class=style1>Please enter your last name!</span></p>';

}

if (preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $trimmed['emale'])) {

$e = $trimmed['emale'];

} else {

echo '<p><span class=style1>Please enter a valid email address!</span></p>';

}

if (is_numeric($trimmed['quantity']))

$q = (int)$trimmed['quantity'];

else{

echo '<p>Please enter a valid Quantity!</p>';

}

$met_of_pay = $_POST['mop'];

if ($fn && $ln && $e && $q)

{

list($cnfrm,$ref) = $cdb->into_db($fn,$ln,$e,$q,$met_of_pay);

if($cnfrm)

{

header("Location: thanks.php");//.?fn=$fn" . "ln=$ln" . "$val=TRUE");

                                      ob_end_flush();

}

}

else

{

echo'<span class=style1>& resubmit the form</span>';

}

}?>

<form name="form1" method="post" action="form.php">

  <table width="75%" height="162" border="1" align="left" bordercolor="#FFFFFF" bgcolor="#FFFFFF">

    <tr>

      <td width="18%">First Name:</td>

      <td width="82%"><input type="text" name="f_name" size="30" maxlength="60" /value="<?php //if(isset($_POST['f_name']))echo htmlspecialchars($_POST['f_name'])?>"></td>

    </tr>

    <tr>

      <td>Last Name:</td>

      <td><input type="text" name="l_name" size="30" maxlength="60" value="<?php //if(isset($_POST['l_name']))echo htmlspecialchars($_POST['l_name'])?>"></td>

    </tr>

    <tr>

      <td>Email:</td>

      <td><input type="text" name="emale"></td>

    </tr>

    <tr>

      <td>Method of Payment:</td>

      <td><select name="mop">

  <?php

  $method_of_payment = array(1 => 'Credit Card', 'Master Card', 'Pay Pal');

  foreach($method_of_payment as $key => $value)

  echo "<option value=\"$key\">$value</option>\n";

  ?>

        </select></td>

    </tr>

    <tr>

      <td>Quantity:</td>

      <td><input type="text" name="quantity" size="9" maxlength="4" value="<?php //if(isset($_POST['quantity']))echo htmlspecialchars($_POST['quantity'])?>"></td>

    </tr>

  </table>

<p> </p>

<p> </p>

<p> </p>

<p> </p>

<p> </p>

<p>

  <input type="submit" name="submit" value="sumit">

  <input type="hidden" name="submitted" value="TRUE" />

</form>

 

</p>

<p>CALL US ANY TIME: <span class="style1">0800 0800 0800</span></p>

</body>

</html>

 

__________________________________________________________________________________________________________________________________________

and this is my connect.php

 

<?php

 

$host="localhost";

 

class class_mysql

{

  var $host = "localhost";

  var $into_db_id = "";

  var $selectid = "";

  var $updateid = "";

  var $insertid = "";

  var $result = array();

 

  function db_con()

  {

 

  $dbname = "dts_powersaver";

  $loginname = "root";

  $loginpass = "";

 

//   $dbname = "hajj";

//   $loginname = "";

//   $loginpass = "";

 

  $dbhost = "localhost";

 

      $db=mysql_connect($host, $loginname, $loginpass) or die("Could not connect!");

      mysql_select_db($dbname);

  return $db;

  }

 

  function into_db($f_n,$l_n,$e,$qn,$mop)

  {

    $f_n = mysql_real_escape_string($f_n,$this->db_con());

$l_n = mysql_real_escape_string($l_n,$this->db_con());

$e = mysql_real_escape_string($e,$this->db_con());

$qn = mysql_real_escape_string($qn,$this->db_con());

 

$counter_file = "./count.dat";

$lines = file($counter_file);

$counter = (int) $lines[0];

 

$counter++;

 

//echo "You're visitor No. $counter.";

 

if(!($fp = fopen($counter_file, "w")))

{

  die ("Cannot open $counter_file.");

}

fwrite($fp, $counter);

fclose($fp);

 

$q = "SELECT CID FROM Customer WHERE Email='$e'";

$r = mysql_query($q,$this->db_con());

if(mysql_num_rows($r) == 0)

{

$q = "INSERT INTO Customer(First_Name,Last_Name,Email)VALUES('$f_n','$l_n','$e')";

@mysql_query($q,$this->db_con());

$q = "SELECT CID FROM Customer WHERE email='$e'";

    $r = @mysql_query($q,$this->db_con());

    }

//$row = mysqli_fetch_array($r,MYSQLI_ASSOC);

while($row = mysql_fetch_array($r))

$q = "INSERT INTO order_cust (CID,Prod_Ref,Quantity,Method_of_Pay) VALUES ({$row['CID']},$counter,$qn,$mop)";

if(@mysql_query($q,$this->db_con()))

{

return array (TRUE,$counter);

}

else

{

    echo "Cannot update into Database";//$this->getError("Mysql error.");

    }

  }

}

  ?>

Regards

sK

Link to comment
Share on other sites

have you read the sticky on header issues?

you need to move the header command to before any output

<html>
<head>
<title>Order Online</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {
   font-family: Arial, Helvetica, sans-serif;
   font-weight: bold;
}
-->
</style>
</head>

is output and needs to be after the header command

also try to use [ code][/code] tags around code

 

Scott.

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.