i am new to sql queries.
Kindly can anyone guide me where to start learning using storedprocedure in php and mysql ?
please help me with this eg:
I have 1 table Bill:
columns as: Title | Qty | Price | Total
in frontend i ask user for: Title | Qty | Price
when user save the form, i want database to show:
Title | Qty | Price | Total
Here, i want to use Stored procedure to be executed on Total with the following:
Qty * Price
So, i want everything user add a new bill the total is calculated using stored procedure, and store total in db for that bill and show it in frontend.
Help with a eg. would be great and thankful.
there are many ways to do this task. but I'll show you one:
//store the variable
$title = $_POST['Title'];
$qty = $_POST['Qty'];
$price = $_POST['Price'];
//connect to database
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'rootpassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
//sql syntax
$sql = 'INSERT INTO Bill (Title,Qty,Price,Total) VALUES ( ".$title.", ".$qty.", ".$price.", ".$qty * $price." )';
//select tabel
mysql_select_db('your_table_name');
//insert into tabel
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
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.