Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Form Calculation Before Database Insertion


My problem is that i want to make a form where will be made calculations and after the calculation are made, the user should press submit and then, all the values from the form should be inseted into a database.

My code is writen under these lines, but all I want to do is the value code to be calculated from Nume and Prenume (for example, if the Nume value is 2 and Prenume value is 3, in the form the value of code should be 5. Code=Nume+Prenume, but i don't know how to write to make the calculation in real time. Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Getting Primary Key Value Of Last Database Insertion
I have a very simple issue.  I have a bunch of data I'm inserting into a database to create an article.  When complete, I want to redirect to the article, but I need the node_id.  It just so happens that the node_id is the Primary key and is automatically generated by mySQL at insertion time.  Is there an easy way to get the value of the Primary key for the most recent insertion?

Preparing Text For Insertion Into Database
I insert text into a MySQL Database using a TEXT field. PHP syntax is:

$query = "INSERT INTO data (text_field) VALUES('$text_field')";

The problem is, when the user has an apostroph (like "friggin' cool") in the text, MySQL misinterprets it, and the query is invalid. Is there a PHP function that formats the that input so it can be entered into the database?

Today's Date In Database Insertion
How do I insert today's date in a certain database row without using the date() function for a string?  For example, when you use PHPMyAdmin to insert a new table row and there's a column with the type "date", it gives you options such as CURDATE, NOW, etc.  How would I use that in a database query?

Attaching Variables To A Database Positioning Calculation
I have 16 database fields:

p1_id | p2_id | p3_id | p4_id | p5_id | p6_id | p7_id | p8_id
pts_1 | pts_2 | pts_3 | pts_4 | pts_5 | pts_6 | pts_7 | pts_8

How it works is, the *_id fields contain the users ID number. The pts_* field contains a numeric score, the number after pts_ corrisponds to the user field (so the number in pts_5 belongs to p5_id).

What I wish to do is determine 1st, 2nd, 3rd.... 8th positions, depending on the highest number (highest number = 1st, lowest = 8th) then give them a variable, which I need for later on in my script to send messages to each user telling them where they have come etc.

As an example, this is how I've done it for just 2 users:

<?php
if($p1_pts > $p2_pts) {
$1st = $p1_id;
$2nd = $p2_id;
} else {
$1nd = $p2_id;
$2nd = $p1_id;
}
?>

I need to do it for 2 users, 4, 6 and 8 users seperatly, the above is okay for 2 users but my mind is boggled for any more users!

Calculation Form
I need to build a calculation form.. basically they click a couple radio buttons from features they want and then the user enter's in the number of words of the document and then they hit "calculate" button and it gives them an estimate for a quote. Need a little help with the structure of the form, anyone shed some light?

Complicated Email Parse Or Text Extraction And Database Insertion
I am trying to strip some data out of numerous emails and place it in
my database. I know that this seems as if it has been done before.
But, this is a little different. First, the numerous emails all have a
set of data that needs to be extracted and inserted into the database.
Some of the data in the email is id, name, address, city, state, zip,
company, etc. The catch is that the date is formated and presented
differently in each email. Take into consideration the following email
examples:

- excert from email #1
ID:.............. 12345
Name:............ JOHN DOE
Address:......... PO BOX 9999
City:............ Somecity
State:........... CA
Zip Code:........ 90210 ....

Generate An Html Form, To Be Submitted For Insertion To A 3rd Table
1. display a form consisting of radio buttons and check boxes. multiple selection of check boxes per radio button basically.

I got this part done, it displays the data in the form which is being pulled from two separate tables.

2. Insert for each check box a record into a third table of the check box and radio button.

this is what i have thus far and I'm not really sure why it's not working from what i can see step by step it should be inserting the records, these arrays are the most terrible thing i can think of having to do. Code:

SQL Insertion Problem
I am have a little problem with inserting some info into my database. What I would like to do is be able to select the last row of my database because my data is sorted by database the most recent date will be at the bottom of my database.

This script is being used for uploading files and when the user uploads files the date is stored with it thats why the date is the most recent at the bottom.

Anyways I understand that mysql_num_rows($var); will tell me how many rows of data are in my database. I have tried a million times to use a for loop to get the last row of data.

There has to be some way to just extract the last row of data from my database I just dont know how.

Date Insertion ?
I am inserting date in a table as following....is it the correct way ?

$dt = getdate();
$day = $dt['mday'];
$month = $dt['mon'];
$year = $dt['year'];
$dt = $year."-".$month."-".$day;

$query = "insert into Articles(PostedDate) values('".$dt."')";
$result = mysql_query($query,$con);

Stripping Chars Before SQl Insertion
I have a form with an input box that the user puts in a dollar amount. I dont want them to put a dollar sign or anything else apart from the currency amount (1.00, 1,658 etc). How would I achieve this?

Problem With Ip Address Insertion
This problem is manifesting it self outside PHP at the level of directly typing commands into the MYSQL application itself. Obviously it is going to have the same effect inside PHP. I need escape characters or something but nothing I have tried works.

typing the command
INSERT INTO table(ip,commentfield)VALUES ("111.222.333", 'old spammer');

results in only the characters 111 appearing in the ip field . It is defined as a char 16 field.

Multiple Insertion Querry
I have an array of data in PHP. I would like to insert each member of the
array into it's own row in SQL. The array is of variable length, so it
would have to be dynamic code. How would I go about this? Would I stick
the SQL querry generation and actual querry into a while loop? This would
generate a lot of traffic between the SQL server and the PHP script.

The arrays are each over 1000 members long, however, this is an rare admin
script that will be run roughly 4 times a year, so I guess it isn't that
bad. If possible however, I would like to do it in one querry. Is that
possible? I thought I heard somewhere that it's impossible to run more
that one querry at once through PHP as a failsafe for users sticking bad
data into forms. (ie, you cant do: "querry1; querry2;", you have to do
"querry1;" querry it, then do "querry2;"

Insertion Of Data Not In Order
I have a slight problem with inserting data into MySQL tables with PHP. So far, everything that is entered into my form does get inserted correctly, meaning all data is added successfully to their respective columns. However, sometimes when I insert another set of data, it appears on top of the preceding data. The first column in my table is called 'employid', it set to auto_increment and primary. Code:

Stripping Chars Before SQl Insertion
I have a form with an input box that the user puts in a dollar amount. I dont want them to put a dollar sign or anything else apart from the currency amount (1.00, 1,658 etc)
How would I achieve this?

String Insertion And Extraction
is there a function to replace  a section af a string with another regardless of the values and to do the reverse i.e.

$srt1 = "ABCDEFGHIJKLM")
$str2 = "XY

// insert $str2 in to $str1 [3] and [4]
$srt1 = "ABCXYFGHIJKLM")
AND
$str = $str1 positions [7] and [8]
$str = "HI";

I want to do some incripion on text. OR will I have to create something?

After Mysql Insertion Another Row Is Added
on the site i am developing i have noticed after a database insertion is made, mysql insert another row (but only the id increments by 1)

if i insert:

id---name---age---country
1 ---Graham---28---Scotland

right after this will be:

2 ---blank---blank---blank

i checked the inserts carefully it all seems fine, then tried LIMIT 1, with the INSERT INTO but that didn't work, any ideas on what this could be?

Mysql Data Insertion
I am using this script to load a file into the webserver, and store the path in the database. That is working fine. However, when I try to upload other information from the same field I keep getting the field name in the data. Code:

Image Upload & MySQL Insertion
I am having a bit of trouble getting my script to work. I am trying to get a file (image) to be uploaded to a specified path and insert the file name, a timestamp, and id into my MySQL database to later pull the files that I uploaded out from the DB and display them on a page. Could someone tell me what I am doing wrong? It displays the image upload form, just as I want it to, but if you submit the form, it just takes you back to it and does nothing. It doesn't give any errors, upload the file, nor does it insert anything into the DB.

Stop Sql Insertion On Every Page Refresh
The page has a form which basically take in a file name, and and upload button does the uploading.

the php code at the top of the page takes the file name and insert the name into a database.

the problem is: everytime the user presses the refresh button, a new entry is inserted into the database.

Two-Dimensional Array Insertion And Print
1. return results from an Oracle query into an array. there are 3 fields and approx. 2,000 records.

2. insert the results into an array of some type, inside of a loop, obviously.

3. print the results so i can verify the query is working.

PHP Code:

Code Insertion + Escape Chars
I'm updating my scripts a bit, and I was wondering how I could insert data in a textarea just by clicking a button. For instance add a Url or a smily ... (just like in these forums when posting)

An other question, how do I make sure I don't need to use a to get a ' For instance if I want to add content containing a " ' " I need to write "hello I'm ..."

Image Insertion And Retrievel Using Mysql
I've managed to get images inserted in mysql and can pull them out for display, but for some reason it looks as if the bottom 4th of the jpg photos do not show. Is there a space limitation for blobs?

Drag And Drop Insertion In MySql
I'm developing a site in PHP/MySql that requires Ajax for this feature
: The user read an article and if ever he likes it he can drag it and
drop it into his "basket". Then when he'll consult its account he'll
found that article.

Drop Down Menus And Mysql Insertion
I'm looking to create drop down boxes for a user to select the date and then have it insert what they select for month, day, year, hour, minutes and insert it into mysql. It needs to be organized in a timestamp like so: 2007-02-28 21:06:40

I've created the drop down boxes and it works pretty well: Code:

Date Calculation In PHP
Hi!

I'm trying to get a date with PHP i.e. 14 days from now in yyyy-mm-dd or any other format like print (date("Y-m-d")) + 14 days.

Is there an easy way to do this??

Binary Calculation
I need some way of determining which bits are set in a binary number.

eg.

Decimal Number: 40
Binary Number: 00101000

How can I determine that the binary equivalent of 8 and 32 are set??

Duration Calculation
I had a look at a post here in regards to this issue but after it i was blank. I gave it a shot and i got a wrong value.

Time Calculation With Php
users of my web site enter time and distance of a run the did into a http-form. the data will be processed by a php-script and stored in an mysql-database. what i want to do is to calculate from the data what time they needed for a 1k-run -> i.e.: if one runs 12k in one hour it will be 5 minutes for 1k.

the problem is, the data from the textfield of the form comes in as a string and hence i just can't divide the data ride away.

time input should look like: 1:00:00
distance input should look like: 12
and output should look like: 0:05:00

any ideas?

PHP Math Calculation
I am trying to perform a simple calculation from variables passed from a form. The code is as follows:

<?php
echo "Bonus for the year: <b>";
$x = (($awage * $nibt) + ($awage * $ratio));
$x = number_format($x, 2);
print $x;
echo "</b><p>";
$xtmp = ($x + $qtr);
print $xtmp;?>

The calculation multiplies two different values (based on values from the previous page), and then sets it equal to $x. The first calculation prints fine, but when I try to add it to $qtr (also passed via radio button from previous page), it doesn't calculate correctly.

I found that if I hard-code the values for $x and $qtr after I print $x, then it will calculate correctly. I am thinking that I am using the variables incorrectly somewhere.

Leave Calculation
for example, for the first 2 years, he does not has bonus leave, on the third year onwards, he has 1 day increase. by default, he has 18 days leave, on the third year, he can carry forward the 10 days from the previous year, now, he has 28 days leave plus 1 day bonus leave = 29 days. same with the fourth year, he can carry forward 10 days, so, he has 39 days leave plus 1 day bonus leave = 40 days.

if he apply 2 days leave in the first 2 years, the balance is 16 days. on the third year, he only can carry forward 10 days only, not 16 days. if he apply 12 days leave in the first 2 years, the balance is 6 days. on the third year, he only can carry forward 6 days only, not 10 days. this is the problem that u don't know how to fix, can you teach me?

Time Calculation
does anyone know how to calculate time difference between 2 periods of time(say 12:00 am and 1:00am) ?? i have been trying to come up with an algorithm but bugs keep crawling in.


Date Calculation
I would like to make a selection from the database in the following manner ie which is created in the last 1 week or last 2 weeks. There is one field named created_date in the database and the date is in the format yyyy-mm-dd. I have seen date calculations based on month and year but didn't see one on a week basis.

Date Calculation
I am learning PHP/MySQL, and I am also writting the Library Management
System to make sure that I practice what I am leaning.

My Problem is:

I want to capture the date when the library user borrow the book and then
check that date to see if the book have exceeded the number of days (to
calculate how many days user has stayed with the book once she return it).
Please help me how I can do that. I am using mysql as my database.

Days Calculation
i can't seem to get this what im trying to do is work out the elapsed time in DAYS from 2 dates code is:

             $time_now = time();
             $d2 = date('Y-m-d H:i:s', $time_now);
             $d1 = date('Y-m-d H:i:s', strtotime($ng_date));
             $days = ceil(($d1 - $d2) / (60 * 60 * 24));
when echoing out it produces:

2007-06-02 16:53:24
2007-08-27 18:00:51
which is right, but $days echoes out as 0.

Add Trailing Zero To Calculation
I am pulling a couple of numbers from a database (productcost and productprice).  I am trying to subtract the cost from the price to calculate the profit of the item.  I have this part working with no problem. My problem lies when the final number has a trailing zero it will drop that number (i.e. 1.2 as opposed to 1.20)

Here is what I am using:

$profit = $row_viewcoils['ProductPrice'] - $row_viewcoils['ProductCost'];
      echo $profit;

Insertion Of Data Into MySQL Tables By Date?
My assumption is that when you insert data into a MySQL table, the latest data is put on the bottom, and is thus the farthest from the beginning of any search you'd initiate. I assume the search starts at the top-most row (oldest) and works it's way down.

Since I'd like to search the latest data, and pull only about 10 rows of data, the most efficient manner would be to have the tables structured such that the newest content was always on top (a date-wise descendent structure).

There must be a way to create a table such that any insertion would be put on top. I know I can ORDER BY date when doing a SELECT command, but that would entail searching the entire data set; isn't there a way to define the table ahead of time such that a date/time column is always ranked in descending order?

Avatar Script Insertion Vulnerability (Security)
Looking at http://secunia.com/advisories/17295/ , it seems possible to embed javascript in images in a special way.

So, if a user provides an avatar or an image url like this pointing to an external site, they will be able to hack accounts.

Do you know how this can be avoided? And/or, how sites like vbulletin/phpbb/smf type of applications protect users from this?

Leap Year Calculation
how can i incorporate leap year also at my below codes PHP Code:

Create A Function To Do The Calculation
writing the following lines of code into a simple
function. I'd like to be able to create a function to do the
calculation, then feed the $a, $b, or $c variable into it.

<?php $a = $kerryvotes/$votes;
$kpercentage = $a * 100;
$kpercent = round($kpercentage, 0);
?>

<?php $b = $bushvotes/$votes;
$bpercentage = $b * 100;
$bpercent = round($bpercentage, 0);
?>
<?php $c = $nadervotes/$votes;
$npercentage = $c * 100;
$npercent = round($npercentage, 0);
?>

Avg Time On-site Calculation
I am collecting the date and time of each visit to pages on a web-site into a MySQL DB. Would now like to use that info to calculate the avg time a visitor has been on the site.
What is the best way to do that?

Date Comparison Calculation
I want build and extract data from a mysql table by date. The problem is that my table data needs to be by date range as follows.

Example: key field is DATE field
row 1: 02-19-96 to 02-06-97
row 2: 02-07-97 to 01-27-98
row 3: 01-28-98 to 02-15-99

and the input for the query will come from a FORM input (without range), example:
Enter birthday input value could be 05-13-96 How can I query the table and select the row with the correct range.

Relative Link Calculation
I am implementing a semi-template system via the use of 'include()' which pull from files from in a dir in the document root. But as the depth of the files in the direcotry structure changes, you can well imagine that relative links get messued up as the include runs the script from the path from which it was called not the path from which it got the file. So basically I'd just like to know if anyone has a smart script to calculate reltative links.

Date Input And Calculation
I need to input the time into a form for a start time and an end time, and write it to the database. I also need to calculate the time to see the time elasped, and input that into a database, for a field of time spent.

OT: Franchisee Area Calculation
I've searched the web for weeks (on and off) but can't find any
information about the topic.

A client wants to set up a franchisee structure and track this
information via a database.

I've never done this and uncertain of how I would do it.

Initially the client only wants state by state franchisees but I can
see that this could eventually be scaled to districts/areas.

To compound matters, my client is wanting this to work in any country.

Problem With Date Calculation
im a really noob fresh starting php programmer:P

but i need really to solve this problem witha php script:

I can rent a flat from 01/01/90 to 01/01/2011
ill rent that flat for a time that i will choice from that timeline above,
so ie I could rent that flat from 01/15/93 to 01/15/95.

well at this point i need to know how mani days for each year i rent that
flat in the above case it would be like this:

year 1990= 0
year 1991=0
year 1992=0
year 1993 = 15
year 1994=365
year 1995=15
year 1996=0
year 199...
year 2011=0

since im really noob could plz give me:
1)an input about the logic process to use to write a script
2)wich command i should use
3)a whole script or an idea of it if u can

i know the days from and to each period, i cant just find the right routine
to get the above datas

Simple Date Calculation
I have two dates and I would like to get the difference in minutes:

$date1 = date("Y-m-d H:s:i"); // now
$date2 = // a date in the same format as above just retrieved from the database it will be in the future

So I would like to get just the minutes between them.

Simple Calculation Between Array
i have two arrays :

$quantity = array(1,2,3);
$price = array(15.45,12.3,23);

how do i make those two arrays for a multiply calculation like this :

$total = $quantity * $price;

i want the total of the calculations in a new array

Street Address Calculation
Does anyone know of a tutorial or script that will calculate driving distance between two street addresses? I have only found ones that does it base on zip codes.

Calculation And Limiting Decimals
I have a greater total of 61 and I score 45

$i= 61;
$y= 45;

$pct = ($i /$y) * 100;

one is tha correct Two how can i limit the number that result diplays (0.987654321 - i just want .987)

and how do i turn off this error message???

Warning: Division by zero in localhostinfo.php on line xxx


Copyright © 2005-08 www.BigResource.com, All rights reserved