Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,259 members, 7,807,890 topics. Date: Wednesday, 24 April 2024 at 09:58 PM

Pls Programmers In PHP And MYSQL Help Out On This - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Pls Programmers In PHP And MYSQL Help Out On This (1281 Views)

Pls Programmers Help With Similarities Of Pseudocode & Algorithm / Android Quiz Application With Json Parser, Php And Mysql Database / Why Do Seun Dont Like Php And Mysql Programmers (2) (3) (4)

(1) (Reply) (Go Down)

Pls Programmers In PHP And MYSQL Help Out On This by dmark4real: 5:26pm On Nov 01, 2012
Pls my honorable programmers in the house, i have a problem with the following code: I want the code to calculate the amount whenever the quantity and the rate is selected but i get undefined index and i need the page to automatically calculate and display the amount when the quantity and rate is selected without having to click anything. I hope anyone understand this.


<?php $qty = $_GET['qty'];
$rate = $_GET['rate'];

$amt = ($qty*$rate);


?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="get">
<table width="200" border="1">
<tr>
<td>Qty</td>
<td><select name="qty"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>&nbsp;</td>
</tr>
<tr>
<td>Description</td>
<td><input type="text" name="des" />&nbsp;</td>
</tr>
<tr>
<td>Rate</td>
<td><input type="text" name="rate"/>&nbsp;</td>
</tr>
<tr>
<td>Amount</td>
<td><input type="text" name="amount" value="<?php echo $amt; ?>" />&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="submit" value="Save" />&nbsp;</td>
</tr>
</table>


The info will be sent into the database when the button save is clicked.




</form>
Re: Pls Programmers In PHP And MYSQL Help Out On This by jboy01(m): 6:24pm On Nov 01, 2012
dmark4real: Pls my honorable programmers in the house, i have a problem with the following code: I want the code to calculate the amount whenever the quantity and the rate is selected but i get undefined index and i need the page to automatically calculate and display the amount when the quantity and rate is selected without having to click anything. I hope anyone understand this.


<?php $qty = $_GET['qty'];
$rate = $_GET['rate'];

$amt = ($qty*$rate);


?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="get">
<table width="200" border="1">
<tr>
<td>Qty</td>
<td><select name="qty"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>&nbsp;</td>
</tr>
<tr>
<td>Description</td>
<td><input type="text" name="des" />&nbsp;</td>
</tr>
<tr>
<td>Rate</td>
<td><input type="text" name="rate"/>&nbsp;</td>
</tr>
<tr>
<td>Amount</td>
<td><input type="text" name="amount" value="<?php echo $amt; ?>" />&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="submit" value="Save" />&nbsp;</td>
</tr>
</table>


The info will be sent into the database when the button save is clicked.




</form>
With my little knowledge, I think web application development is not like pc application, the page need to load to carry out the instructions that is the ($AMT*$RATE). And for the system to carry out the insructions, u need to click on the submit button.
Re: Pls Programmers In PHP And MYSQL Help Out On This by Nobody: 9:19pm On Nov 01, 2012
the php code part will run everytime, including the first moment you try to load the page
you need to add a condition to the php code to run only when the submit button is clicked


<?php
if(isset($_GET['qty']) && trim($_GET['qty'])!="" && isset($_GET['rate']) && trim($_GET['rate'])!="" )
{
$qty = (int)$_GET['qty'];
$rate = (int)$_GET['rate'];
$amt = ($qty*$rate);

//<add code to insert to database here>

}

?>
Re: Pls Programmers In PHP And MYSQL Help Out On This by bakenda(m): 12:01pm On Nov 02, 2012
dmark4real: i need the page to automatically calculate and display the amount when the quantity and rate is selected without having to click anything. I hope anyone understand this.

You will need JavaScript to do that, look into the JavaScript onBlur event.
Re: Pls Programmers In PHP And MYSQL Help Out On This by ChelaTheGreat: 12:47pm On Nov 02, 2012

//You'll need JavaScript for it. And maybe AJAX if you eventually want to store the results in your MySql database.
<script>
calcThis=function(){
var rate = document.getElementById("rate" ).value ;
var quantity = document.getElementById("quantity" ).value ;
var amount = rate * quantity ;
//OR var amount = (int)(rate) * (int)(quantity) ;
document.getElementById("amount" ).innerHTML = amount ;
/* If you want to store in your MySql database, its more complex:
You can define a function tied in to a javascript AJAX library like jquery.js or prototype.js
PostViaAjax(rate,quantity,amount) ; */
}
</script>

<label>Quantity:</label>
<input value='20' name='quantity' placeholder='quantity' id='quantity' onchange = "calcThis()" />
<br/>
<label>Rate:</label>
<select onchange = "calcThis()" name='rate' id='rate'>
<option value='5'>5 Naira</option>
<option value='10'>10 Naira</option>
</select>
<br/>
<label>Amount:</label>
<span id='amount'></span>

2 Likes

Re: Pls Programmers In PHP And MYSQL Help Out On This by olyjosh(m): 2:12pm On Nov 09, 2012
php is a server side scripting language. It perform it operation on the server, hence can not perform such operation without loading the browser.

The solution to this problem is to use java script events onBlur or onChange to handle the event that will be carried out immeditely the mouse is no more on the form element (e.g textField) then pass the answer to a variable that you will now send via GET or POST request to php processing script on ur web-server. such that the variable is the anwser that is been passed to ur database.

Take a look at what @ChelaTheGreat is having for you

1 Like

Re: Pls Programmers In PHP And MYSQL Help Out On This by dmark4real: 11:18am On Nov 16, 2012
Thanks to you all. I tried javascript and it works tanks alot.

(1) (Reply)

Help Me Fix My Java Login Code Error / Need Help With AIML On Android / HELP HELP HELP ........I NEED ADMIN FEAUTURES IN MY FORUM

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 24
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.