Picasso_ss Posted August 16, 2007 Share Posted August 16, 2007 Hello, I'm a totaly newbie in php but I LOVE IT. 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. Thank you very much for helping. HERE IS THE CODE: <html> <head> <title>Add New MySQL User</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php if(isset($_POST['add'])) { include 'configuri/config.php'; include 'configuri/opendb.php'; $nume = $_POST['nume']; $prenume = $_POST['prenume']; $code = $_POST['code']; $query = "INSERT INTO TEST (cod, nume, prenume) VALUES ('$code', '$nume', '$prenume')"; mysql_query($query) or die('Error, insert query failed'); echo "Am adaugat o noua inregistrare"; } else { ?> <form method="post" name="myform" id="myform"> <table width="400" border="0" cellspacing="1" cellpadding="3"> <tr> <td width="100">nume</td> <td><input name="nume" type="text" id="nume"></td> </tr> <tr> <td width="100">prenume</td> <td><input name="prenume" type="text" id="prenume"></td> </tr> <tr> <td width="100">code</td> <td><input name="code" type="text" id="code"></td> </tr> <tr> <td width="100"> </td> <td> </td> </tr> <tr> <td width="100"> </td> <td><input name="add" type="submit" id="add" value="Add New User"> </td> </tr> </table></form> <?php } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/65228-form-calculation-before-database-insertion/ Share on other sites More sharing options...
r-it Posted August 16, 2007 Share Posted August 16, 2007 you will have to use javascript for that, use an onblur function for teh second field so that when you click anywhere else on the page, the javascript function is initialised, and the calculated field is populated Quote Link to comment https://forums.phpfreaks.com/topic/65228-form-calculation-before-database-insertion/#findComment-325750 Share on other sites More sharing options...
Picasso_ss Posted August 17, 2007 Author Share Posted August 17, 2007 Thank you but I'll beg you to look at my code and write me the sentence if it's possible. Quote Link to comment https://forums.phpfreaks.com/topic/65228-form-calculation-before-database-insertion/#findComment-326501 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.