Code: Select all
<?php
// Get and strip values from form
$title= $data['title'];
$descript= $data['descript'];
$proof= $data['proof'];
$min= $data['min'];
$amountworkers= $data['amountworkers'];
$perperson= $data['perperson'];
$createuser_id= $data['createuser_id'];
$user_name= $data['user_name'];
$ujob_id= $data['id'];
$feature= $data['feature'];
$tbl_name = "fulldata";
// Check the form token
if(isset($data['proof']) && isset($data['title']) && isset($data['descript']) && isset($data['title']) && isset($data['min']) && isset($data['amountworkers']) && isset($data['perperson']) && isset($data['createuser_id']) && isset($data['user_name']) && isset($data['id']))
{
if($data['token'] != $_SESSION['token'])
{
die('Invalid Token');
}
// token is now valid, process rest of form
if (isset($data['submit'])){
if ($data['done']){
echo "The form has already been processed";}
else {
// calculate the cost of the job
$total_cost = round(($data['amountworkers'] * $data['perperson'] + $data['feature']) * 1.05, 2);
$user_cost = $_SESSION['user_money'];
try {
if ($perperson < 0.10) {
throw new Exception("perperson is to small"); // more than 0.10 per person?
}
if ($total_cost > $user_cost) {
throw new Exception("incorrect funds"); // does the user have the correct amount of money?
}
// if the user does have enough money process the update in DB
else{
session_start();
$_SESSION['user_money'] = round($user_cost - $total_cost, 2);
$sql = "UPDATE `users`
SET users.user_money = round($user_cost - $total_cost, 2)
WHERE users.id = '$_SESSION[user_id]'";
$result = mysql_query($sql)
or die('Invalid query: ' . $sql . ' - Error is ' . mysql_error());
}
// Insert data into mysql
$sql= mysql_query("INSERT INTO $tbl_name(job_id, title, descript, proof, min, amountworkers, perperson, createuser_id, user_name, date)VALUES('$ujob_id', '$title', '$descript', '$proof', '$min', '$amountworkers', '$perperson', '$createuser_id', '$user_name',now())") or die( mysql_error() );
// has the user paid for the service or isit free bouns job?
if ($total_cost > 2.00)
{
$sql = "UPDATE `fulldata`
SET fulldata.deposit = 1
WHERE fulldata.job_id = '$ujob_id'";
$result = mysql_query($sql)
or die('Invalid query: ' . $sql . ' - Error is ' . mysql_error());
}
if ($feature > 0.10)
{
$sql = "UPDATE `fulldata`
SET fulldata.feature = 1
WHERE fulldata.job_id = '$ujob_id'";
$result = mysql_query($sql)
or die('Invalid query: ' . $sql . ' - Error is ' . mysql_error());
}
// if successfully insert data into database, displays message "Successful".
if($sql){
echo "Thank you for submiting your job, our team will now take a look and approve very soon ";
echo "<BR>";
echo "$feature";
echo "<a href='/jobs.php'>Click here to go back to Minute Workers</a>";
}
else {
echo "ERROR";
}
} catch (Exception $e) {
// There has been an error
echo "Each person needs more than 0.10";
} catch (Exception $e) {
// There has been an error
echo "You have insufficient funds to create this job, please allow room for a 5% charge onto your job total cost.";
echo "<BR>";
echo "<BR>";
echo "Your total cost is: <b>$$total_cost</b>";
echo "<BR>";
echo "Your current deposit amount is: <b>$$_SESSION[user_money]</b>";
echo "<BR>";
echo "<BR>";
echo "Please click back and try again.";
}
}
}
}
line 105-END: I am trying to catch the conditions
So the problem is if one of the exceptions is triggered it is always the secound catch blocks error messaged displayed. How can i have each condition with its own error message when triggered.