简体   繁体   中英

How to pass a variable from one file to another in php

I am calling a value from my SQL database like so

echo "<td>" . $row['name'] . "</td>";

I am then trying to read that value in another file

$order_content .=  "<td>" . $_SESSION['5050duckdown'][$key]['name'] . "</td>";

I have had some issues with other portions of passing data across as you can see here . It helped me with one portion of my app but I have been unable to replicate it to the other variables. Any help would be greatly appreciated, I have been stuck on this for so long now I don't know what ways up..

UPDATE: Order form

<html>
<head>
<title>Duvets & Pillows - Contact Us</title>
<meta name="Description" content="To purchase high quality curtain fabric, duvets, cushions, blinds and pillows. Also fabric for upholstery.">
<meta name="Keywords" content="Curtains, duvets, cushions, blinds, pillows, upholstery, fabric">
<meta name="verify-v1" content="kJvtha3o1pD/wr0uhRW2cxZqbf5YFn4psvLGt6xwqtg=" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body class="mainBody">
<table align="center" border="0" width="780" height="100%" cellspacing="0" cellpadding="0">
    <tr>
        <td height="63"><img src="images/Interface/topbanner.jpg" alt="" width="780" height="63"></td>
    </tr>
    <tr>

        <td height="63" bgcolor="#233368"><a href="http://www.homefabrics.co.nz"><img src="images/Interface/logo-panel.gif" border="0"></a></td>

    </tr>
    <tr>
        <td valign="top"><table border="0" height="100%" cellspacing="0" cellpadding="0">
    <tr>
        <td width="158" valign="top" bgcolor="#233368" style="width: 158px; border-width: 1px 0px 0px 0px; border-color: #fff; border-style: solid;"><span class="mainmenu"><a href="Page-page=1.php.html">Home</a></span><br><span class="mainmenu"><a href="Page-page=2.php.html">About Us</a></span><br><span class="mainmenu"><a href="Page-page=3.php.html">About Feather & Down</a></span><br><span class="mainmenu"><a href="Page-page=5.php.html">Duvets</a></span><br><span class="mainmenu"><a href="Page-page=8.php.html">Goose Down Pillows</a></span><br><span class="mainmenu"><a href="Page-page=9.php.html">Feather Beds</a></span><br><span class="mainmenuon">Contact Us</span></td>
        <td width="100%" valign="top" class="borderrightbottom" style="padding: 30px 40px 30px 40px;">
        <h1>Contact Us</h1>
        <p><b>HOME FABRICS LIMITED</b></p>
        <p><b>Free delivery nationwide.</b></p>
        <p>Telephone: &nbsp;09 486 1103<br />
        Facsimile: 09 489 6136.<br />
        Email: <a href="mailto:sales@homefabrics.co.nz">sales@homefabrics.co.nz</a></p><p>Website:&nbsp;<a href="http://www.homefabrics.co.nz/">www.homefabrics.co.nz</a></p><p>28 Hurstmere Road<br />PO Box 33-024<br />Takapuna Beach<br />Auckland</p><h2>ORDER FORM</h2><br /> 

        <p><i>Required fields are marked with</i> <b>*</b></p>

<form action="orderformDNP.php" method="post"
onsubmit="document.getElementById('myButton').disabled=true;
document.getElementById('myButton').value='Submitting...';"
>

<table width="496" border="0" style="border-width: 1px; border-color:#E5E5E5;
border-style: solid;">
    <tr>
        <td width="40%">
            Name: *
        </td>
        <td width="60%">
            <input type="text" name="yourname" />
        </td>
    </tr>
    <tr>
        <td width="40%">
            Phone Number: *
        </td>
        <td width="60%">
            <input type="text" name="phonenumber" />
        </td>
    </tr>
    <tr>
        <td width="40%">
            Mobile Number: 
        </td>
        <td width="60%">
            <input type="text" name="mobilenumber" />
        </td>
    </tr>
    <tr>
        <td width="40%">
            E-mail: *
        </td>
        <td width="60%">
            <input type="text" name="email" />
        </td>
    </tr>
    <tr>
        <td width="40%">
            Deliver Address: *
        </td>
        <td width="60%">
            <textarea name="deliveryaddress" rows="3" cols="40"></textarea>
        </td>
    </tr>
 </table>
 </br>


<!-- this is the ordering part of the form --!>

 <h3>Duvets</h3>

<?php

//Start session
    //session_start();

    //Include database connection details
    require_once('config.php');

    //Array to store validation errors
    $errmsg_arr = array();

    //Validation error flag
    $errflag = false;

    //Connect to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
        die('Failed to connect to server: ' . mysql_error());
    }

    //Select database
    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
        die("Unable to select database");
    }



$result = mysql_query("SELECT * FROM 5050goosedown ORDER BY price ASC");

echo "<table border='0' width='496'>
<tr>
<th width='30%'><b>50/50 Goose Down:</b></th>
<th width='30%'><i>Normal Fill / Our Fill</i></th>
<th width='12.5%'><i>Old Price</i></th>
<th width='12.5%'><i>Price</i></th>
<th width='12.5%'><i>Quantity</i></th>
</tr>";

$i = 1;
while($row = mysql_fetch_array($result)){
    echo "<tr bgcolor='#F5F5F5'>";
  if($i%2 == 0){
      echo "<tr bgcolor='#E5E5E5'>";
  }
  $i++;

  if (($row['width'] ==0) && ($row['height']== 0)){
    echo "<td>" . $row['name'] . "</td>";
  }
  else {
    echo "<td>" . $row['name'] . "   -" . $row['width'] . "/" . $row['height'] .  "</td>";
  }
  echo "<td>" . $row['normal_fill'] . "/" . $row['our_fill'] . "</td>";
  if ($row['old_price'] !=0){
    echo "<td>" . $row['old_price'] . "</td>";
  }
  else {
    echo "<td></td>";
  }
  echo "<td>" . $row['price'] . "</td>";

  echo '<td><select name="5050goosedown[' . $row['goosedown_id'] . ']">'
                ."<option value=''> 0 </option>
                <option>1</option>
                <option>2</option>
                <option>3</option>
                <option>4</option>
                <option>5</option>
                <option>6</option>
                <option>7</option>
                <option>8</option>
            </select>
        </td>";
  echo "</tr>";
  }
echo "</table>";

?>
</br></br>
<?php

//Start session
    //session_start();

    //Include database connection details
    require_once('config.php');

    //Array to store validation errors
    $errmsg_arr = array();

    //Validation error flag
    $errflag = false;

    //Connect to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
        die('Failed to connect to server: ' . mysql_error());
    }

    //Select database
    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
        die("Unable to select database");
    }


$result = mysql_query("SELECT * FROM 5050duckdown ORDER BY price ASC");

echo "<table border='0' width='496'>
<tr>
<th width='30%'><b>50/50 Duck Down:</b></th>
<th width='30%'><i>Normal Fill / Our Fill</i></th>
<th width='12.5%'><i>Price</i></th>
<th width='12.5%'><i>Quantity</i></th>
</tr>";

$i = 1;
while($row = mysql_fetch_array($result)){
    echo "<tr bgcolor='#F5F5F5'>";
  if($i%2 == 0){
      echo "<tr bgcolor='#E5E5E5'>";
  }
  $i++;

  if (($row['width'] ==0) && ($row['height']== 0)){
    echo "<td>" . $row['name'] . "</td>";
  }
  else {
    echo "<td>" . $row['name'] . "   -" . $row['width'] . "/" . $row['height'] .  "</td>";
  }
  echo "<td>" . $row['normal_fill'] . "/" . $row['our_fill'] . "</td>";
  echo "<td>" . $row['price'] . "</td>";
  echo '<td><select name="5050duckdown[' . $row['duckdown_id'] . ']">'
                ."<option value=''> 0 </option>
                <option>1</option>
                <option>2</option>
                <option>3</option>
                <option>4</option>
                <option>5</option>
                <option>6</option>
                <option>7</option>
                <option>8</option>
            </select>
        </td>";
  echo "</tr>";
  }
echo "</table>";

?>
</br></br>
<?php

//Start session
    //session_start();

    //Include database connection details
    require_once('config.php');

    //Array to store validation errors
    $errmsg_arr = array();

    //Validation error flag
    $errflag = false;

    //Connect to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
        die('Failed to connect to server: ' . mysql_error());
    }

    //Select database
    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
        die("Unable to select database");
    }


$result = mysql_query("SELECT * FROM 955goosedown ORDER BY price ASC");

echo "<table border='0' width='496'>
<tr>
<th width='30%'><b>95/5 Goose Down:</b></th>
<th width='30%'><i>Normal Fill / Our Fill</i></th>
<th width='12.5%'><i>Old Price</i></th>
<th width='12.5%'><i>Price</i></th>
<th width='12.5%'><i>Quantity</i></th>
</tr>";

$i = 1;
while($row = mysql_fetch_array($result)){
    echo "<tr bgcolor='#F5F5F5'>";
  if($i%2 == 0){
      echo "<tr bgcolor='#E5E5E5'>";
  }
  $i++;

  if (($row['width'] ==0) && ($row['height']== 0)){
    echo "<td>" . $row['name'] . "</td>";
  }
  else {
    echo "<td>" . $row['name'] . "   -" . $row['width'] . "/" . $row['height'] .  "</td>";
  }
  echo "<td>" . $row['normal_fill'] . "/" . $row['our_fill'] . "</td>";
  if ($row['old_price'] !=0){
    echo "<td>" . $row['old_price'] . "</td>";
  }
  else {
    echo "<td></td>";
  }
  echo "<td>" . $row['price'] . "</td>";
  echo '<td><select name="955goosedown[' . $row['955goosedown_id'] . ']">'
                ."<option value=''> 0 </option>
                <option>1</option>
                <option>2</option>
                <option>3</option>
                <option>4</option>
                <option>5</option>
                <option>6</option>
                <option>7</option>
                <option>8</option>
            </select>
        </td>";
  echo "</tr>";
  }
echo "</table>";

?>
</br>
<h3>Pillows</h3>

<?php

//Start session
    //session_start();

    //Include database connection details
    require_once('config.php');

    //Array to store validation errors
    $errmsg_arr = array();

    //Validation error flag
    $errflag = false;

    //Connect to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
        die('Failed to connect to server: ' . mysql_error());
    }

    //Select database
    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
        die("Unable to select database");
    }


$result = mysql_query("SELECT * FROM goosedownpillows ORDER BY price ASC");

echo "<table border='0' width='496'>
<tr>
<th width='62.5%'><b>Goose Down Pillows:</b></th>
<th width='12.5%'><i>Price</i></th>
<th width='12.5%'><i>Quantity</i></th>
</tr>";

$i = 1;
while($row = mysql_fetch_array($result)){
    echo "<tr bgcolor='#F5F5F5'>";
  if($i%2 == 0){
      echo "<tr bgcolor='#E5E5E5'>";
  }
  $i++;

  echo "<td>" . $row['name'] ."</td>";
  echo "<td>" . $row['price'] . "</td>";
  echo '<td><select name="goosedownpillows[' . $row['goosedownpillows_id'] . ']">'
                ."<option value=''> 0 </option>
                <option>1</option>
                <option>2</option>
                <option>3</option>
                <option>4</option>
                <option>5</option>
                <option>6</option>
                <option>7</option>
                <option>8</option>
            </select>
        </td>";
  echo "</tr>";
  }
echo "</table>";

?>
</br>
<h3>Feather Mattress Toppers</h3>

<?php

//Start session
    //session_start();

    //Include database connection details
    require_once('config.php');

    //Array to store validation errors
    $errmsg_arr = array();

    //Validation error flag
    $errflag = false;

    //Connect to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
        die('Failed to connect to server: ' . mysql_error());
    }

    //Select database
    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
        die("Unable to select database");
    }


$result = mysql_query("SELECT * FROM feathermattresstoppers ORDER BY price ASC");

echo "<table border='0' width='496'>
<tr>
<th width='62.5%'><b>95/5 Mattress Toppers:</b></th>
<th width='12.5%'><i>Old Price</i></th>
<th width='12.5%'><i>Price</i></th>
<th width='12.5%'><i>Quantity</i></th>
</tr>";

$i = 1;
while($row = mysql_fetch_array($result)){
    echo "<tr bgcolor='#F5F5F5'>";
  if($i%2 == 0){
      echo "<tr bgcolor='#E5E5E5'>";
  }
  $i++;

  if (($row['width'] ==0) && ($row['height']== 0)){
    echo "<td>" . $row['name'] . "</td>";
  }
  else {
    echo "<td>" . $row['name'] . "   -" . $row['width'] . "/" . $row['height'] .  "</td>";
  }
  if ($row['old_price'] !=0){
    echo "<td>" . $row['old_price'] . "</td>";
  }
  else {
    echo "<td></td>";
  }
  echo "<td>" . $row['price'] . "</td>";
  echo '<td><select name="feathermattresstoppers[' . $row['feathermattresstoppers_id'] . ']">'
                ."<option value=''> 0 </option>
                <option>1</option>
                <option>2</option>
                <option>3</option>
                <option>4</option>
                <option>5</option>
                <option>6</option>
                <option>7</option>
                <option>8</option>
            </select>
        </td>";
  echo "</tr>";
  }
echo "</table>";

?>





<p><b>Additional Info:</b><br />
<textarea name="comments" rows="10" cols="40"></textarea></p>
</br></br>

Access code: <input type="text" name="code" /><br />
Please enter <i>MYCODE</i> above. </br></br>

<input type="submit" value="Submit" id="myButton" />

        </td>

    </tr>
</table>

</td>
    </tr>
</table>
</body>
</html>

Email form (this is upposed to recive the values from order form)

<?php
    session_start();

    $body_items = '';
    $total_price = 0;


    /* Set Redgraves Email address, so they receive the orders  */
    $myemail  = "kcwebz@gmail.com";

    /* Check all form inputs using check_input function */
    $yourname = check_input($_POST['yourname'], "Enter your name");
    $phonenumber = check_input($_POST['phonenumber'], "Enter your phone number");
    $mobilenumber = check_input($_POST['mobilenumber']);
    $email    = check_input($_POST['email'], "Enter your E-mail address");
    $deliveryaddress = check_input($_POST['deliveryaddress'], "Enter your delivery address");

    $comments = check_input($_POST['comments']);

    $random = substr(number_format(time() * rand(),0,'',''),0,10);

    $goosedown_id = ($_POST[$row['goosedown_id']]); 




    if (strtolower($_POST['code']) != 'mycode') 
    {
        die('Wrong access code');
    }

    /* If e-mail is not valid show error message */
    if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
    {
        show_error("E-mail address not valid");
    }

    /* If phone number has characters show error message */
    if (preg_match("/\D/",$phonenumber))
    {
        die("Please enter numbers only for Phone Number");
    }

    /* If mobile number has characters show error message */
    if (preg_match("/\D/",$mobilenumber))
    {
        die("Please enter numbers only for Mobile Number");
    }


    // 5050duckdown
    $flag = 0;
    $i = 1;
    $order_content = '';
    foreach ($_POST['5050goosedown'] as $key => $value ) {
        if ($value > 0) {
            $flag = 1;
            if($i%2 == 0)
                $order_content .= "<tr bgcolor='#E5E5E5'>";
            else
                $order_content .= "<tr bgcolor='#F5F5F5'>";
            $i++;

            if (($row['width'] ==0) && ($row['height']== 0))
                $order_content .=  "<td>" . $_SESSION['5050goosedown'][$key]['name'] . "</td>";
            else
                $order_content .=  "<td>" . $_SESSION['5050goosedown'][$key]['name'] . "   -" . $_SESSION['5050goosedown'][$key]['width'] . "/" . $_SESSION['5050goosedown'][$key]['height'] .  "</td>";

            $order_content .= "<td>" . $_SESSION['5050goosedown'][$key]['price'] . "</td>";

            $order_content .= "<td>" . $value . "</td>";

            $sub = $_SESSION['5050goosedown'][$key]['price'] * $value;
            $total_price += $sub;
            $order_content .= "<td>" . $sub . "</td></tr>";
        }
    }

    if ($flag == 1) {
        $body_items .= "<table border='0' width='600'>
                            <tr>
                                <th width='30%'><b>50/50 Goose Down:</b></th>
                                <th width='12.5%'><i>Item Price</i></th>
                                <th width='12.5%'><i>Quantity</i></th>
                                <th width='12.5%'><i>Price</i></th>
                            </tr>";
        $body_items .= $order_content;
        $body_items .= '</table><br /><br />';
    }

    //////////////
    $flag = 0;
    $i = 1;
    $order_content = '';
    foreach ($_POST['5050duckdown'] as $key => $value ) {
        if ($value > 0) {
            $flag = 1;
            if($i%2 == 0)
                $order_content .= "<tr bgcolor='#E5E5E5'>";
            else
                $order_content .= "<tr bgcolor='#F5F5F5'>";
            $i++;

            if (($row['width'] ==0) && ($row['height']== 0))
                $order_content .=  "<td>" . $_SESSION['5050duckdown'][$key]['name'] . "</td>";
            else
                $order_content .=  "<td>" . $_SESSION['5050duckdown'][$key]['name'] . "   -" . $_SESSION['5050duckdown'][$key]['width'] . "/" . $_SESSION['5050duckdown'][$key]['height'] .  "</td>";

            $order_content .= "<td>" . $_SESSION['5050duckdown'][$key]['price'] . "</td>";

            $order_content .= "<td>" . $value . "</td>";

            $sub = $_SESSION['5050duckdown'][$key]['price'] * $value;
            $total_price += $sub;
            $order_content .= "<td>" . $sub . "</td></tr>";
        }
    }

    if ($flag == 1) {
        $body_items .= "<table border='0' width='600'>
                            <tr>
                                <th width='30%'><b>50/50 Duck Down:</b></th>
                                <th width='12.5%'><i>Item Price</i></th>
                                <th width='12.5%'><i>Quantity</i></th>
                                <th width='12.5%'><i>Price</i></th>
                            </tr>";
        $body_items .= $order_content;
        $body_items .= '</table><br /><br />';
    }

    /////////////////
    $flag = 0;
    $i = 1;
    $order_content = '';
    foreach ($_POST['955goosedown'] as $key => $value ) {
        if ($value > 0) {
            $flag = 1;
            if($i%2 == 0)
                $order_content .= "<tr bgcolor='#E5E5E5'>";
            else
                $order_content .= "<tr bgcolor='#F5F5F5'>";
            $i++;

            if (($row['width'] ==0) && ($row['height']== 0))
                $order_content .=  "<td>" . $_SESSION['955goosedown'][$key]['name'] . "</td>";
            else
                $order_content .=  "<td>" . $_SESSION['955goosedown'][$key]['name'] . "   -" . $_SESSION['955goosedown'][$key]['width'] . "/" . $_SESSION['955goosedown'][$key]['height'] .  "</td>";

            $order_content .= "<td>" . $_SESSION['955goosedown'][$key]['price'] . "</td>";

            $order_content .= "<td>" . $value . "</td>";

            $sub = $_SESSION['955goosedown'][$key]['price'] * $value;
            $total_price += $sub;
            $order_content .= "<td>" . $sub . "</td></tr>";
        }
    }

    if ($flag == 1) {
        $body_items .= "<table border='0' width='600'>
                            <tr>
                                <th width='30%'><b>95/5 Goose Down:</b></th>
                                <th width='12.5%'><i>Item Price</i></th>
                                <th width='12.5%'><i>Quantity</i></th>
                                <th width='12.5%'><i>Price</i></th>
                            </tr>";
        $body_items .= $order_content;
        $body_items .= '</table><br /><br />';
    }

    //////
    $flag = 0;
    $i = 1;
    $order_content = '';
    foreach ($_POST['goosedownpillows'] as $key => $value ) {
        if ($value > 0) {
            $flag = 1;
            if($i%2 == 0)
                $order_content .= "<tr bgcolor='#E5E5E5'>";
            else
                $order_content .= "<tr bgcolor='#F5F5F5'>";
            $i++;

            if (($row['width'] ==0) && ($row['height']== 0))
                $order_content .=  "<td>" . $_SESSION['goosedownpillows'][$key]['name'] . "</td>";
            else
                $order_content .=  "<td>" . $_SESSION['goosedownpillows'][$key]['name'] . "   -" . $_SESSION['goosedownpillows'][$key]['width'] . "/" . $_SESSION['goosedownpillows'][$key]['height'] .  "</td>";

            $order_content .= "<td>" . $_SESSION['goosedownpillows'][$key]['price'] . "</td>";

            $order_content .= "<td>" . $value . "</td>";

            $sub = $_SESSION['goosedownpillows'][$key]['price'] * $value;
            $total_price += $sub;
            $order_content .= "<td>" . $sub . "</td></tr>";
        }
    }

    if ($flag == 1) {
        $body_items .= "<table border='0' width='600'>
                            <tr>
                                <th width='30%'><b>Goose Down Pillows:</b></th>
                                <th width='12.5%'><i>Item Price</i></th>
                                <th width='12.5%'><i>Quantity</i></th>
                                <th width='12.5%'><i>Price</i></th>
                            </tr>";
        $body_items .= $order_content;
        $body_items .= '</table><br /><br />';
    }

    //////
    $flag = 0;
    $i = 1;
    $order_content = '';
    foreach ($_POST['feathermattresstoppers'] as $key => $value ) {
        if ($value > 0) {
            $flag = 1;
            if($i%2 == 0)
                $order_content .= "<tr bgcolor='#E5E5E5'>";
            else
                $order_content .= "<tr bgcolor='#F5F5F5'>";
            $i++;

            if (($row['width'] ==0) && ($row['height']== 0))
                $order_content .=  "<td>" . $_SESSION['feathermattresstoppers'][$key]['name'] . "</td>";
            else
                $order_content .=  "<td>" . $_SESSION['feathermattresstoppers'][$key]['name'] . "   -" . $_SESSION['feathermattresstoppers'][$key]['width'] . "/" . $_SESSION['feathermattresstoppers'][$key]['height'] .  "</td>";

            $order_content .= "<td>" . $_SESSION['feathermattresstoppers'][$key]['price'] . "</td>";

            $order_content .= "<td>" . $value . "</td>";

            $sub = $_SESSION['feathermattresstoppers'][$key]['price'] * $value;
            $total_price += $sub;
            $order_content .= "<td>" . $sub . "</td></tr>";
        }
    }

    if ($flag == 1) {
        $body_items .= "<table border='0' width='600'>
                            <tr>
                                <th width='30%'><b>95/5 Mattress Toppers:</b></th>
                                <th width='12.5%'><i>Item Price</i></th>
                                <th width='12.5%'><i>Quantity</i></th>
                                <th width='12.5%'><i>Price</i></th>
                            </tr>";
        $body_items .= $order_content;
        $body_items .= '</table><br /><br />';
    }
    $body_items .= "<br /><b>Total: $total_price</b></b></b>";



/*-------------------First Email--------------------*/

    /* Set Email for Redgraves, so they can for-full the order form */
    $message = "A order form has been submitted by: $yourname<br /><br />

    Order number :<u>$random</u><br /><br />

    <b>Name:</b> $yourname<br />
    <b>E-mail:</b> $email<br />
    <b>Phone Number:</b> $phonenumber<br />
    <b>Mobile Number:</b> $mobilenumber<br />
    <b>Delivery Address:</b> $deliveryaddress<br />
    <b>Comments:</b> $comments<br /><br />

    $body_items


    <br /><br />**End of message**
    ";

/* Send the message using mail() function */
    $header= "MIME-Version: 1.0\r\n";
    $header.= "Content-type: text/html\r\n";
    mail($myemail, "Order Submitted", $message, $header);

    /* Send the message using mail() function */
    //mail($myemail, "Order Submitted", $message);

/*---------------Second Email---------------------*/    

    /* This email is to confirm the order and act as a receipt to the purchaser */
    $respond_message = "Order Completed<br /><br />

    Your order has been submitted! details are as follows<br /><br />

    <b>Name:</b> $yourname<br />
    <b>E-mail:</b> $email<br />
    <b>Phone Number:</b> $phonenumber<br />
    <b>Mobile Number:</b> $mobilenumber<br />
    <b>Delivery Address:</b> $deliveryaddress<br />
    <b>Comments:</b> $comments<br /><br />

    $body_items


    <br /><b>Reference Number:</b> <u>$random</u><br /><br />

    Please make payment using the refrence number above within 7 working days or your order will be canceled <br />
    ASB 000-0000-0000-00 ";

    /* Send the message using mail() function */
    $headers= "MIME-Version: 1.0\r\n";
    $headers.= "Content-type: text/html\r\n";
    mail($email, "Thank you for your order", $respond_message, $headers);


    /* Redirect visitor to the thank you page */
    header('Location: thankyou.html');
exit();




/* Functions we used */
function check_input($data, $problem='')
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    if ($problem && strlen($data) == 0)
    {
        show_error($problem);
    }
    return $data;
}




function show_error($myError)
{
?>
    <html>
    <body>

    <b>Please correct the following error:</b><br />
    <?php echo $myError; ?>

    </body>
    </html>
<?php
exit();
}
?>

the order form should produce a table like this.. as you can see the value are missing from it.

在此处输入图片说明

Check this out:

echo "<td>" . $row['name'] . "</td>\n";
$_SESSION['name'] = $row['name'];

$order_content .= "<td>" . $_SESSION['5050duckdown'][$key]['name'] . "</td>\n";

But please review the code $_SESSION['5050duckdown'][$key]['name'] if it's right. If not, then just chance it to $_SESSION['5050duckdown'] . $_SESSION[$key] . $_SESSION['name'] $_SESSION['5050duckdown'] . $_SESSION[$key] . $_SESSION['name']

But please, don't forget the session_start(); function before the opening <html> tag, and the first file where we tried to assign the row into a session must be run first before running the second file where the session assigning to a variable.

You have 2 option:

Either u create cookie or session and you can also tr global variable.

Use this code like.

<?php    
session_start();

  //print_r($_SESSION);
  echo "<td>" . $row['name'] . "</td>\n";
  $_SESSION['name'] = $row['name'];

?>

and use it in other file like.

$order_content .= "<td>" . $_SESSION['name'] . "</td>\n";

May be its works.

you can also use ? operator

   Ex. 
   // order_form.php

   $id = 7;          //and you want sent on order_edit.php
   order_edit.php?id=$id;      // set variable in anchor tag or where you want


  // order_edit.php 

  $id = $_GET['id'];       // get value of id from url 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM