Jump to content

Form calculation before database insertion


Picasso_ss

Recommended Posts

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.