0

Hello I'm making a basic budgeting system. Over the past week I've been moving my files from a localhost to a webserver and have been encountering server errors 500. Ussually I've been able to resolve them by changing my code a little (declaring the charset or getting rid of certain bits of php) however I now have a page which isn't working and a page which are working who have almost identical php the only difference being variables. Here's my code for the one that isn't working:

<?php
header('charset=utf-8');
session_start();
include_once 'checkLogin.php';
include_once 'dbconnect.php';
error_reporting( ~E_DEPRECATED & ~E_NOTICE );
$id=$_SESSION['user'];
//this display the budget
if(isset($_GET['view'])){
$mid = $_GET['mortgageId'];//to use to get other stuff
$id = $_SESSION['id'];
$sql="SELECT * FROM  Mortgage WHERE mortgageId='$mid'";
$sql1="SELECT * FROM  Mortgage_Allocation WHERE  mortgageId='$mid'";
$res = mysql_query($sql);
$res1 = mysql_query($sql1);
$row=mysql_fetch_array($res);
$row1=mysql_fetch_array($res1);
$Type=$row['Type'];
$Early=$row['earlyRepayment'];
$interest=$row1['Interest'];
$Ini=$row1['InitialSum'];
$month=$row1['monthlyPay'];
$length=$row1['Length'];

if(isset($_GET['delete'])){
$savingsId = $_GET['savingsId'];
$sql="DELETE FROM Mortgage WHERE mortgageId='$mid'";
$sql1="DELETE FROM Mortgage_Allocation WHERE mortgageId='$mid'";
$res=mysql_query($sql);
$res1=mysql_query($sql1);
if($res=$res1 and $res=1){
header('Location:home.php')
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<link rel='stylesheet' typ='text/css' href='pageLayout.css'>
<style>
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
</style>
</head>
<body><!--use this to insert into table?-->
<ul>
<li><a href='home.php'>Return Home.</a></li>
<li><a href='newfile.html'>Make a new budget.</a></</li>
<li><a href='displayValues.php'>View a budget.</a></li>
<li><a href='AddonMenu.php'>A list of addons.</a></li>
<li><a href='logout.php'>Logout.</a></li>
</ul>
<table style='width:75%'>
<tr>
<th>Info</th>
<th></th>
</tr>
<tr><td>Type</td>
<td><input type='text' placeholder='<?php echo $Type ?>'/></td></tr>
<tr><td>Total Amount</td>
<td><input type='number' placeholder='<?php $TotalAmt=$Ini *pow(1 + $Interest/1,1*$Time);
$Total=round($Total, 2); echo $TotalAmt; ?>'/></td></tr>
<tr><td>Interest</td>
<td><input type='number' placeholder='<?php echo $Interest; ?>'/></td></tr>
<tr><td>Monthly Payback</td>
<td><input type='number' placeholder='<?php echo $monthlyPay; ?>'/></td></tr>
<tr><td>Length in years</td>
<td><input type='text' placeholder='<?php echo $length; ?>'/></td></tr>
<tr><td>Early Repayment Available</td>
<td><input type='text' placeholder='<?php echo $Early; ?>'/></td></tr>
<tr><td>InitialAmount</td>
<td><input type='text' placeholder='<?php echo $Ini; ?>'/></td></tr>
</table>
<form action="home.php">
<input type="submit" value="Return Home" />
</form>
</body>
</html>

I know mysql is deprecated/doesn't work on newer version but it works on this server. Also there isn't much of an issue with encrypting plaintext. The error I get in firefox console is

'The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.'

As well as the get request failing because of an internal server error. I'm checking the Get request and the information is correct so I honestly have no idea what's wrong. I'd like to say it's the servers fault but given how hasn't been the past few times I think I'm just missing something. Here's the similar page that does work:

<?php
session_start();
include_once 'checkLogin.php';
include_once 'dbconnect.php';
error_reporting( ~E_DEPRECATED & ~E_NOTICE );
$id=$_SESSION['user'];
//this display the budget
if(isset($_GET['edit'])){
$bid = $_GET['id'];//due to latest development is actually budget id
$id = $_SESSION['id'];
$sql="SELECT * FROM  Budget WHERE BudgetId='$bid'";
$res = mysql_query($sql);
$row=mysql_fetch_array($res);
$Sal=$row['Sal'];//UserId and Monthyear are in [0] & [1]
$TaxReb = $row['TaxReb'];
$RetInv = $row['RetInv'];
$IntSave = $row['IntSave'];
$Pen = $row['Pen'];
$Dividends = $row['Dividends'];
$Wages = $row['Wages'];
$Loans = $row['Loans'];
$Benefits = $row['Benefits'];
$IncOther = $row['IncOther'];
$Tax = $row['Tax'];
$Groc = $row['Groc'];
$Take = $row['Take'];
$Rent = $row['Rent'];
$Elec = $row['Elec'];
$Trans = $row['Trans'];
$Mort = $row['Mort'];
$LoanPay = $row['LoanPay'];
$Goods = $row['Goods'];
$ExpOther = $row['ExpOther'];
$TotalInc = $row['TotalInc'];
$TotalExp = $row['TotalExp'];
$NetInc=$row['NetInc'];
$result=$res;
}
//this will delete
if(isset($_GET['delete'])){
$bid = $_GET['id'];
// Delete the row
$sql="DELETE FROM Budget WHERE BudgetId='$bid'";
$res = mysql_query($sql);
if ($res) {
echo 'Deleted';
header("Location: home.php");
} else {
echo "Error deleting record: " . $conn->error;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' typ='text/css' href='pageLayout.css'>
</head>
<style>
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
</style>
<body><!--use this to insert into table?-->
<ul>
<li><a href='home.php'>Return Home.</a></li>
<li><a href='newfile.html'>Make a new budget.</a></</li>
<li><a href='displayValues.php'>View a budget.</a></li>
<li><a href='AddonMenu.php'>A list of addons.</a></li>
<li><a href='logout.php'>Logout.</a></li>
<?php echo $result;?>
</ul>

<form method='post' action='updateVals.php'> <!--when finished it will send the values to be updated -->
<table style='width:75%'>
<tr>
 <th>Income Name</th>
 <th>Value</th>
</tr>
<tr><td>Salary</td>
 <td><input type='number' name='Sal' placeholder='<?php echo $Sal ?>'/></td></tr>
<tr><td>Tax rebates</td>
 <td><input type='number' name='TaxReb' placeholder='<?php echo $TaxReb ?>'/></td></tr>
<tr><td>Returns on investments</td>
 <td><input type='number' name='RetInv' placeholder='<?php echo $RetInv ?>'/></td></tr>
<tr><td>Interest on savings</td>
 <td><input type='number' name='IntSave' placeholder='<?php echo $IntSave?>'/></td></tr>
 <tr><td>Pensions</td>
 <td><input type='number' name='Pen' placeholder='<?php echo $Pen?>'/> </td></tr>
 <tr><td>Dividends</td><!-- might read div as something else-->
 <td><input type='number' name='Dividends' placeholder='<?php echo $Dividends?>'/></td></tr>
 <tr><td>Wages</td>
 <td><input type='number' name='Wages' placeholder='<?php echo $Wages ?>'/></td></tr>
 <tr><td>Loans</td>
 <td><input type='number' name='Loans' placeholder='<?php echo $Loans?>'/></td></tr>
 <tr><td>Benefits</td>
 <td><input type='number' name='Benefits' placeholder='<?php echo $Benefits ?>'/></td></tr>
 <tr><td>Other</td>
 <td><input type='number' name='IncOther' placeholder='<?php echo $IncOther ?>'/></td></tr>
 <tr>
 <th>Expense Name</th>
 <th></th>
 </tr>
 <tr><td>Taxation</td>
 <td><input type='number' name='Tax' placeholder='<?php echo $Tax ?>'/></td></tr>
 <tr><td>Groceries</td>
 <td><input type='number' name='Groc' placeholder='<?php echo $Groc ?>'/></td></tr>
 <tr><td>Restaurants/ Take Away</td>
 <td><input type='number' name='Take' placeholder='<?php echo $Take ?>'/></td></tr>
 <tr><td>Rent</td>
 <td><input type='number' name='Rent' placeholder='<?php echo $Rent?>'/></td></tr>
 <tr><td>Electricity</td>
 <td><input type='number' name='Elec' placeholder='<?php echo $Elec?>'/></td></tr>
 <tr><td>Transport</td>
 <td><input type='number' name='Trans' placeholder='<?php echo $Trans?>'/></td></tr>
 <tr><td>Mortgage</td>
 <td><input type='number' name='Mort' placeholder='<?php echo $Mort?>'/></td></tr>
 <tr><td>Loan Payback</td>
 <td><input type='number' name='LoanPay' placeholder='<?php echo $LoanPay?>'/></td></tr>
 <tr><td>Goods and Services</td>
 <td><input type='number' name='Goods' placeholder='<?php echo $Goods?>'/></td></tr>
 <tr><td>Other</td>
 <td><input type='number' name='ExpOther' placeholder='<?php echo $ExpOther?>'/></td></tr>
 <tr><td>Total Income</td>
   <td><input type='number' name='TotalInc' placeholder='<?php echo $TotalInc?>'/></td></tr>
 <tr><td>Total Expenditure</td>
   <td><input type='number' name='TotalExp' placeholder='<?php echo $TotalExp?>'/></td></tr>
 <tr><td>Balance</td>
   <td><input  type='number' name='NetInc' placeholder='<?php echo $NetInc?>'/></td></tr>
 <tr><td><input type='submit' value='Finish'/></td></tr>
 </table>
 </form>
 </body>
 </html>
  • Add `ini_set('display_errors', 1);` after the `error_reporting()` call, and temporarily change that to `error_reporting(E_ALL);`. Always do this when developing and testing code – Michael Berkowski Mar 28 '17 at 20:06
  • first check file permissions, webserver should have read permission on your scripts – dparoli Mar 28 '17 at 20:10
  • that's only a developer console message. Check your logs instead. – Funk Forty Niner Mar 28 '17 at 20:10
  • `if($res=$res1 and $res=1)` that... is failing. You're assigning rather than comparing. – Funk Forty Niner Mar 28 '17 at 20:12
  • as is `echo 'Deleted'; header("Location: home.php");` which you are clearly outputting before header. – Funk Forty Niner Mar 28 '17 at 20:12
  • Ok I hadn't realised that would happen if I used headers. Changing them to an echoed javascript string fixed this. – M.Skerritt Mar 28 '17 at 20:31
  • If you know `mysql_query` is deprecated, why are you still using it? This code is so full of holes it will whistle if you wave it around. For your own safety this cannot be anywhere near the public internet. Using something like PDO isn't just safer, it's actually easier than banging around with the clunky old `mysql_query` layer. – tadman Mar 28 '17 at 20:45

0 Answers0