Jump to content

Recommended Posts

Hi im tryin to get some calculations done but im not sure wat im doing wrong :( can anyone hlp

<?php
session_start();
if(!session_is_registered(myusername)){
header("location:login.php");
}
echo "Hi $_SESSION[myusername] <br /><br />";
?>
<html>  
  <body>
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="modify"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql= "SELECT * FROM `modify` ORDER BY `ID` ASC";
$result = mysql_query($sql);
$rows = mysql_num_rows($result);
?>
    <form action="count.php" method="post">
<strong><a href="javascript:void(0);" onClick="document.getElementById('tab1').style.display='block';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Pages</a></strong><br />
  <div id="tab1" style="display:none; font-size:11;">   
      Single Sided B&W        
      <input type="radio" name="bw/c" value="1" /><br />
      Double Sided B&W        
      <input type="radio" name="bw/c" value="2"  /><br />  
      Single Sided Colour       
      <input type="radio" name="bw/c" value="3"  /><br />  
      Double Sided Colour       
      <input type="radio" name="bw/c" value="4"  /><br />      

    <?php
echo '<select name="Ptype">';
while($data = mysql_fetch_assoc($result)) {
echo '<option name=bw/c/pt value="'.$data['Valeu'].'">'.$data['Name'].'</option>'."\n";
}
echo '</select>';
?>    

  </div>
  <strong><a href="javascript:void(0);" onClick="document.getElementById('tab2').style.display='block';document.getElementById('tab1').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Binding and Stapling</a></strong><br /> 
      
  <div id="tab2" style="display:none;"> 
      None           
      <input type="radio" name="s/b" value="0"  /><br />
      Spiral         
      <input type="radio" name="s/b" value="1"  /><br />                 
      <select name="Spitype">		         
        <option name="s/b/spty" value="1a" >Cerlox/Comb              
        <option name="s/b/spty" value="1b" >Wireless 		         
        <option name="s/b/spty" value="2c" >Coil 		       
      </select>
      <br>
      Staples        
      <input type="radio" name="s/b" value="2"  /><br />
        <select name="Spitype">		         
        <option name="s/b/stty" value="2a" >Top              
        <option name="s/b/stty" value="2b" >Side 		         
        <option name="s/b/stty" value="2c" >Bottom 		       
      </select><br>
  </div>
<strong><a href="javascript:void(0);" onClick="document.getElementById('tab3').style.display='block';document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Covers</a></strong><br />
          
  <div id="tab3" style="display:none;">
      None<input type="radio" name="c" value="0"  /><br>
      Front Cover<br>
      Standard Front Cover
      <input type="radio" name="c" value="1"  /><br>
      <select name="CovType">		         
        <option name="c/cty" value="1a" >No Printing              
        <option name="c/cty" value="1b" >Print B&W   
        <option name="c/cty" value="1c" >Print Colour 
      </select><br>
      <select name="Ptype">		         
        <option name="bw/c/pt" value="1" selected>[Paper Colour/Type]              
        <option name="bw/c/pt" value="1" >White 		         
        <option name="bw/c/pt" value="2" >Red 		         
        <option name="bw/c/pt" value="3" >Blue 		         
        <option name="bw/c/pt" value="4" >Green       
      </select><br>      
      Standard Back Cover
      <input type="radio" name="c" value="2"  /><br>     
      <select name="CovType">		         
        <option name="c/cty" value="2a" >No Printing              
        <option name="c/cty" value="2b" >Print B&W   
        <option name="c/cty" value="2c" >Print Colour 
      </select><br>
      <select name="Ptype">		         
        <option name="bw/c/pt" value="1" selected>[Paper Colour/Type]              
        <option name="bw/c/pt" value="1" >White 		         
        <option name="bw/c/pt" value="2" >Red 		         
        <option name="bw/c/pt" value="3" >Blue 		         
        <option name="bw/c/pt" value="4" >Green       
      </select><br>
      Premium Back Cover
      <input type="radio" name="c" value="3"  /><br>
      <select name="CovType">		         
        <option name="c/cty" value="3a" >Clear             
        <option name="c/cty" value="3b" >Vinyl Black   
        <option name="c/cty" value="3c" >Linen Blue 
      </select><br>
  </div>
<strong><a href="javascript:void(0);" onClick="document.getElementById('tab4').style.display='block';document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Tabs</a></strong><br />
      
  <div id="tab4" style="display:none;">
      Bank<br>
      <select name="BaType">		         
        <option name="t/tty" value="1a" >Full-cut 5            
      </select><br>
      Font<br>
      <select name="FoType">		         
        <option name="t/tty" value="2a" >Arial         
      </select><br>
      Label<br>
      <input type="text"><br>
      Font Size<br>
       <select name="F/size">
        <option name="t/tty" value="3a" >12            
        <option name="t/tty" value="3b" >10   
        <option name="t/tty" value="3c" >8
       </select><br>
   </div>
<strong><a href="javascript:void(0);" onClick="document.getElementById('tab5').style.display='block';document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Special Instuctions</a></strong><br />
  
   <div id="tab5" style="display:none;">
       <textarea></textarea><br>
       <input type="checkbox" name="si/cty" value="1">Cutting<br>
       <select name="si/cty">
        <option name="si/cty" value="1a" >Horizontal            
        <option name="si/cty" value="1b" >Vertical  
        <option name="si/cty" value="1c" >BlahBlah
       </select><br>
       <input type="checkbox" name="si/fty" value="1">Folding<br>
       <select name="si/fty" >
        <option name="si/fty" value="2a" >Horizontal            
        <option name="si/fty" value="2b" >Vertical  
        <option name="si/fty" value="2c" >BlahBlah
       </select><br>
       <input type="checkbox" name="si/lty" value="1">Laminating<br>
       <select name="si/lty" >
        <option name="si/lty" value="3a" >5mm            
        <option name="si/lty" value="3b" >10mm  
       </select><br>
  </div>  
                        
      <input type="submit" value="Total" />    
    </form>

<?php
require_once ('includes.php');
// set quantity
$quantity = 4;

$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="modify"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql= "SELECT * FROM `modify` ORDER BY `ID` ASC";
$result = mysql_query($sql);
$rows = mysql_num_rows($result);

while($data = mysql_fetch_assoc($result)) {

    $answer = $_POST['bw/c/pt'];
    
     if ($answer == $data['Valeu']) {
        
        $origPrice =  $data['Valeu'] ;
        
    }
    
    else {
       
       
// set original and current unit price
$origPrice = 20;
}
}

       
// set original and current unit price
$currPrice = $origPrice * $quantity;

// calculate difference in price
$tax = 16;
// calculate percentage change in price
$PriceTaxed = round((($currPrice * $tax)/100) + $currPrice,0);

        ?>
    <strong>
  <div id="tab6" style="display:block;">
    <table border="1" cellpadding="5" cellspacing="0" >      
      <tr><td>Quantity</td><td>Cost price Per Page</td><td>Current price Without Vat</td><td>Vat</td><td>Total Cost With Vat</td>      
      </tr>      
      <tr align="center"><td>          
          <?php echo $quantity; ?></td><td>$           
          <?php echo $origPrice; ?></td><td>$           
          <?php echo $currPrice; ?></td><td>          
          <?php echo $tax; ?>%</td><td>$           
          <?php echo $PriceTaxed; ?></td>      
      </tr>    
    </table><br /><br />    
</div>
    <a href="logout.php">leave</a>  

  </body>
</html> 

Link to comment
https://forums.phpfreaks.com/topic/188066-calculations-not-working/
Share on other sites

Ok so i kinda played around and got it working now i jsut need it to select the correct Valeu cause it just keeps selecting the last valeu from my db, i want it select watever value i select from the dropdown menu. Any ideas how to do tht anyone?

<?php
session_start();
if(!session_is_registered(myusername)){
header("location:login.php");
}
echo "Hi $_SESSION[myusername] <br /><br />";
?>
<html>  
  <body>
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="modify"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql= "SELECT * FROM `modify` ORDER BY `ID` ASC";
$result = mysql_query($sql);
$rows = mysql_num_rows($result);
?>
    <form action="count.php" method="post">
<strong><a href="javascript:void(0);" onClick="document.getElementById('tab1').style.display='block';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Pages</a></strong><br />
  <div id="tab1" style="display:none; font-size:11;">   
      Single Sided B&W        
      <input type="radio" name="bw/c" value="1" /><br />
      Double Sided B&W        
      <input type="radio" name="bw/c" value="2"  /><br />  
      Single Sided Colour       
      <input type="radio" name="bw/c" value="3"  /><br />  
      Double Sided Colour       
      <input type="radio" name="bw/c" value="4"  /><br />      

    <?php
echo '<select name="Ptype">';
while($data = mysql_fetch_assoc($result)) {
echo '<option name="bw/c/pt" value="'.$data['Valeu'].'">'.$data['Name'].'</option>'."\n";
}
echo '</select>';
?>    

  </div><!--
  <strong><a href="javascript:void(0);" onClick="document.getElementById('tab2').style.display='block';document.getElementById('tab1').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Binding and Stapling</a></strong><br /> 
      
  <div id="tab2" style="display:none;"> 
      None           
      <input type="radio" name="s/b" value="0"  /><br />
      Spiral         
      <input type="radio" name="s/b" value="1"  /><br />                 
      <select name="Spitype">		         
        <option name="s/b/spty" value="1a" >Cerlox/Comb              
        <option name="s/b/spty" value="1b" >Wireless 		         
        <option name="s/b/spty" value="2c" >Coil 		       
      </select>
      <br>
      Staples        
      <input type="radio" name="s/b" value="2"  /><br />
        <select name="Spitype">		         
        <option name="s/b/stty" value="2a" >Top              
        <option name="s/b/stty" value="2b" >Side 		         
        <option name="s/b/stty" value="2c" >Bottom 		       
      </select><br>
  </div>
<strong><a href="javascript:void(0);" onClick="document.getElementById('tab3').style.display='block';document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Covers</a></strong><br />
          
  <div id="tab3" style="display:none;">
      None<input type="radio" name="c" value="0"  /><br>
      Front Cover<br>
      Standard Front Cover
      <input type="radio" name="c" value="1"  /><br>
      <select name="CovType">		         
        <option name="c/cty" value="1a" >No Printing              
        <option name="c/cty" value="1b" >Print B&W   
        <option name="c/cty" value="1c" >Print Colour 
      </select><br>
      <select name="Ptype">		         
        <option name="bw/c/pt" value="1" selected>[Paper Colour/Type]              
        <option name="bw/c/pt" value="1" >White 		         
        <option name="bw/c/pt" value="2" >Red 		         
        <option name="bw/c/pt" value="3" >Blue 		         
        <option name="bw/c/pt" value="4" >Green       
      </select><br>      
      Standard Back Cover
      <input type="radio" name="c" value="2"  /><br>     
      <select name="CovType">		         
        <option name="c/cty" value="2a" >No Printing              
        <option name="c/cty" value="2b" >Print B&W   
        <option name="c/cty" value="2c" >Print Colour 
      </select><br>
      <select name="Ptype">		         
        <option name="bw/c/pt" value="1" selected>[Paper Colour/Type]              
        <option name="bw/c/pt" value="1" >White 		         
        <option name="bw/c/pt" value="2" >Red 		         
        <option name="bw/c/pt" value="3" >Blue 		         
        <option name="bw/c/pt" value="4" >Green       
      </select><br>
      Premium Back Cover
      <input type="radio" name="c" value="3"  /><br>
      <select name="CovType">		         
        <option name="c/cty" value="3a" >Clear             
        <option name="c/cty" value="3b" >Vinyl Black   
        <option name="c/cty" value="3c" >Linen Blue 
      </select><br>
  </div>
<strong><a href="javascript:void(0);" onClick="document.getElementById('tab4').style.display='block';document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Tabs</a></strong><br />
      
  <div id="tab4" style="display:none;">
      Bank<br>
      <select name="BaType">		         
        <option name="t/tty" value="1a" >Full-cut 5            
      </select><br>
      Font<br>
      <select name="FoType">		         
        <option name="t/tty" value="2a" >Arial         
      </select><br>
      Label<br>
      <input type="text"><br>
      Font Size<br>
       <select name="F/size">
        <option name="t/tty" value="3a" >12            
        <option name="t/tty" value="3b" >10   
        <option name="t/tty" value="3c" >8
       </select><br>
   </div>
<strong><a href="javascript:void(0);" onClick="document.getElementById('tab5').style.display='block';document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Special Instuctions</a></strong><br />
  
   <div id="tab5" style="display:none;">
       <textarea></textarea><br>
       <input type="checkbox" name="si/cty" value="1">Cutting<br>
       <select name="si/cty">
        <option name="si/cty" value="1a" >Horizontal            
        <option name="si/cty" value="1b" >Vertical  
        <option name="si/cty" value="1c" >BlahBlah
       </select><br>
       <input type="checkbox" name="si/fty" value="1">Folding<br>
       <select name="si/fty" >
        <option name="si/fty" value="2a" >Horizontal            
        <option name="si/fty" value="2b" >Vertical  
        <option name="si/fty" value="2c" >BlahBlah
       </select><br>
       <input type="checkbox" name="si/lty" value="1">Laminating<br>
       <select name="si/lty" >
        <option name="si/lty" value="3a" >5mm            
        <option name="si/lty" value="3b" >10mm  
       </select><br>
  </div>  -->
                        
      <input type="submit" value="Total" />    
    </form> 

<?php
require_once ('includes.php');
// set quantity
$quantity = 4;

$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="modify"; // Table name

// Connect to server and select databse.




    $answer = $_POST['bw/c/pt'];
    
     if ($answer == $data['Valeu']) {
     
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql= "SELECT * FROM `modify` WHERE Price = Valeu";
$result = mysql_query($sql);
$rows = mysql_num_rows($result);

while($data = mysql_fetch_assoc($result)) {     
         
        $origPrice = $data['Price'] ; }
        
    }
    
    else {
       
       
// set original and current unit price
$origPrice = 20;
}


       
// set original and current unit price
$currPrice = $origPrice * $quantity;

// calculate difference in price
$tax = 16;
// calculate percentage change in price
$PriceTaxed = round((($currPrice * $tax)/100) + $currPrice,0);

        ?>
    <strong>
  <div id="tab6" style="display:block;">
    <table border="1" cellpadding="5" cellspacing="0" >      
      <tr><td>Quantity</td><td>Cost price Per Page</td><td>Current price Without Vat</td><td>Vat</td><td>Total Cost With Vat</td>      
      </tr>      
      <tr align="center"><td>          
          <?php echo $quantity; ?></td><td>$           
          <?php echo $origPrice; ?></td><td>$           
          <?php echo $currPrice; ?></td><td>          
          <?php echo $tax; ?>%</td><td>$           
          <?php echo $PriceTaxed; ?></td>      
      </tr>    
    </table><br /><br />    
</div>
    <a href="logout.php">leave</a>  

  </body>
</html> 

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.