Jump to content

how to Insert calculate values to database


Tje

Recommended Posts

Hi,

I'm trying to insert calculate values to DB.this is my code

<?php
require('dbconnection.php');



$a=$_POST['a'];
$b=$_POST['b'];

class cal{

 
public function insert($a,$b){

if((($a)&&($b))!="")
{
 $c=$a*$b;

$sql = "INSERT INTO cropplant (sbetweenQ ,sbetweenC ,sbetweenTC ) VALUES ('$a', '$b', '$c')";
$query = mysql_query($sql);
if(!$query)
		{
			echo '<script type="text/javascript">alert("DB Update error ! please Re-enter your details.");</script>'; 
		

		}else
			{
			echo '<script type="text/javascript">alert("New Cropplant Added Successfuly.");</script>'; 
			
		}


}else{

echo"please enter all";
}
}
}


?>

what is the error in this code.please help

Link to comment
Share on other sites

in general, you wouldn't put derived values into a database, but assuming your code is just an example/exercise, you didn't show us the code that's making an instance of your cal class and calling the ->insert() method.

 

also, you should not be using the msyql_ database functions because they are obsolete and will be removed in a future php version, which is interesting because at least one of your earlier threads in this forum was using the mysqli_ database functions.

Link to comment
Share on other sites

1. Not checking if the "a" and "b" POST values are present

2. Defining a class in a file alongside (I think?) regular code

3. Using variable names that have no intrinsic meaning

4. Random indentation style

5. Not sanitizing/validating the form input and/or the a and b values

6. Putting output inside a method when it should be returning success or failure

7. Not actually calling any of the insert() code

8. Using mysql extension instead of PDO or mysqli or something else

Edited by requinix
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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