how do i use exception in php ?

  • Answered
i am working on xampp,making database,and i connect them with php,in one of my table,name vehicle_maintainance,there is an attribute maintain_cost,i want to give exception in php that if maintain_cost is greater than 5,000 then an exception occurs and if not greater then data entered in database table,maintain_cost will not be greater than 5,000,so how can i do this in php? i wrote a code but it doesn't work 5000) { echo 'exception'; } Else { $sql = "INSERT INTO maintainance (repair_cost) VALUES ('$value')"; } $sql = "INSERT INTO maintainance (veh_id,maintain_parts_id,maintain_date,maintain_cost) VALUES ('$value','$value2','$value3','$value4')"; if (!mysql_query($sql)) { die('ERROR: ' . mysql_error()); } mysql_close(); ?>

What is the result you are getting when you run your code? Are you not getting the 'exception' echoed to the screen? If so, you will need to check why. Check to see what the actual value of $value4 is as the statement is simple enough and just checks to see if it is over 5000.

If it is failing to print out the exception, then it is likely that the $value4 is not filling properly from the POST. That is where you should start looking.

Kindest Regards,
Scott M