Link to home
Start Free TrialLog in
Avatar of shruti A
shruti A

asked on

insert retrieved data into another table

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Check out</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
<!--
.style9 {font-size: 95%; font-weight: bold; color: #003300; font-family: Verdana, Arial, Helvetica, sans-serif; }
.style10 {color: #FFFFFF}
-->
</style>
</head>
<body>


<form action="" method="POST">
<?php

 include("includes/db.php");
$total=0;
if(isset( $_POST['checkout'] ) )
{
 
$price = "select cart.p_id,cart.ip_add,cart.qty,products.prd_title,products.prd_price from cart inner join products on cart.p_id =products.prd_id";

   $run_price = mysqli_query($con,$price) ;

  
      while($ppprice = mysqli_fetch_array($run_price)){

         $product_id = $ppprice['p_id'];
         $ip_add = $ppprice['ip_add'];
         $qty = $ppprice['qty'];
         $product_title = $ppprice['prd_title'];
         $product_price = array($ppprice['prd_price']);
        

         $price_sum = array_sum($product_price);

         $total +=$price_sum;
        
        echo '<label>Product Id</label><input type="text" value='.$ppprice['p_id'].'>';
         echo ' <label>Order Id</label><input type="text" value='.$ppprice['ip_add'].'>';

 echo '<label>Quantity</label><input type="text" value='.$ppprice['qty'].'>';

 echo '<label>Product Name</label><input type="text" value='.$ppprice['prd_title'].'>';

 echo '<label>Product Price</label><input type="text" value='.$ppprice['prd_price'].'><br/>';
  


        /* echo "<td>". $product_id ."</td>";
         echo "<td>". $ip_add ."</td>";
         echo "<td>". $qty ."</td>";
         echo "<td>". $product_title ."</td>";
         echo "<td>". $product_price ."</td>";*/

         //echo  $product_price;  
         }   
 echo '<label>Total</label><input type="text" value='.$total.'><br/>';
}

?>
<input type="text" name="cname">
<input type="text" name="address">

<input type="submit" name="place_order" value="place order">


</form>
<?php
if(isset( $_POST['place_order'] ) )
{
$cname = $_POST['cname'];
$address = $_POST['address'];
$price1="insert into order_tab(p_id,ip_add,qty,prd_title,prd_price,c_name,shp_address) VALUES('$p_id','$ip_add','$qty','$prd_title','$prd_price','$cname','$address')";


$q1=mysqli_query($con,$price1) ;
if($q1){

echo "successfull";
}

else
{
echo "not successfull";
}
}

?>
</body>
</html>

Open in new window


I'm here imnserting data into order_tab table with customer name as c_name and shipping address  so while inserting  facing problem not inserting

Notice: Undefined variable: p_id in C:\wamp\www\Electronix_PHP\electronix2\Order.php on line 78

giving error for all the fields
Avatar of Jan Louwerens
Jan Louwerens
Flag of United States of America image

The error message is telling you exactly what's wrong. On line 78 above, you are using a variable named "$p_id" (near the VALUES clause), but nowhere in that file is a "$p_id" variable declared or initialized.
Avatar of skullnobrains
skullnobrains

you probably should change
$product_id = $ppprice['p_id'];

to
$p_id = $ppprice['p_id'];

line 54
it's nice when folks have enough time to ask new questions... but none to close older ones... apparently never ever
bumping forever
39 questions and not a single closure
 ______
< bump >
 ------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Open in new window

.    '                   .  "   '
            .  .  .                 '      '
    "`       .   .
                                     '     '
  .    '      _______________
          ==c(___(o(______(_()
                  \=\
                   )=\
                  //|\\
                 //|| \\
                // ||  \\
               //  ||   \\
              //         \\
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.