Hey guys, yes my problem is very, very trivial and im sure it does not rank importance to be posted but im really frustrated. See my coding was fine as in it executed as i wanted it to and now i dont know why but it isn't and i have zero idea coz i did not change anything. I was testing the webpages and this page all of a sudden did not execute.

the file is also included into another file (the main file) e.g main file is income.php and theres this code :
<?php include "january.php";?>

january.php:

<?php
if($_SESSION['name'])
{
    if(isset($_POST['octsave']))
    {
        $octrent = $_POST['octrent'];
        $octelectric = $_POST['octelectric'];
        $octwater = $_POST['octwater'];
        $octgrocery = $_POST['octgrocery'];
        $octinternet = $_POST['octinternet'];
        $octphone = $_POST['octphone'];
        $octcable = $_POST['octcable'];
        $octhothers = $_POST['octhothers'];
        $octcharity = $_POST['octcharity'];
        $octparents = $_POST['octparents'];
        $octchild = $_POST['octchild'];
        $octtravel = $_POST['octtravel'];
        $octshop = $_POST['octshop'];
        $octeat = $_POST['octeat'];
        $octentertain = $_POST['octentertain'];
        $octmisc = $_POST['octmisc'];
        $octpublic = $_POST['octpublic'];
        $octinsurance = $_POST['octinsurance'];
        $octpay = $_POST['octpay'];
        $octservice = $_POST['octservice'];
        $octpetrol = $_POST['octpetrol'];
        $octmisc = $_POST['octmisc'];
        $octtothers = $_POST['octtothers'];
        $octtax = $_POST['octtax'];
        $omonth = $_POST['oct'];

        if($omonth&&$octrent&&$octelectric&&$octwater&&$octgrocery&&$octinternet&&$octphone&&$octcable&&$octhothers&&$octtax)
        {
            require "connect.php";
            $oname=$_SESSION['name'];
            $octhtotal=$octrent+$octelectric+$octwater+$octgrocery+$octinternet+$octphone+$octcable+$octhothers+$octtax;
            $query=("INSERT INTO house VALUES ('$oname','$omonth','$octrent','$octelectric','$octwater','$octgrocery','$octinternet','$octphone','$octcable','$octhothers','$octtax','$octhtotal')");
            $octhresult=mysql_query($query);
        }

        if($omonth&&$octcharity&&$octparents&&$octchild&&$octtravel&&$octshop&&$octeat&&$octentertain&&$octmisc)
        {
            require "connect.php";
            $oname=$_SESSION['name'];
            $octptotal=$octcharity+$octparents+$octchild+$octtravel+$octshop+$octeat+$octentertain+$octmisc;
            $query=("INSERT INTO personal VALUES ('$oname','$omonth','$octcharity','$octparents','$octchild','$octtravel','$octshop','$octeat','$octentertain','$octmisc','$octptotal')");
            $octpresult=mysql_query($query);
        }

        if($omonth&&$octpublic&&$octinsurance&&$octpay&&$octservice&&$octpetrol&&$octtothers)
        {
            require "connect.php";
            $oname=$_SESSION['name'];
            $octttotal=$octpublic+$octinsurance+$octpay+$octservice+$octpetrol+$octtothers;
            $query=("INSERT INTO transport VALUES ('$oname','$omonth','$octpublic','$octinsurance','$octpay','$octservice','$octpetrol','$octtothers','$octttotal')");
            $octtresult=mysql_query($query);
        }
    }
}
?>
<html>
<body>

<center><div class="tabcontent" id="oct">
<center><h2>October</h2></center>   
    <div style="height:0px;">
        <form method="post" action="expenses.php">
        <input type="hidden" value="October" name="oct">
            <center><div id="Oaccordion" style="height:350px;width:400px;margin-top:30px;">
                <label class="house">HOUSE</label>
                    <table class="thouse" border="1" rules="none" cellpadding="6px" width="400px">
                        <tr>
                        <th></th>
                        <th></th>
                        <th>RM</th>
                        </tr>
                        <tr>
                        <td>Rent/Mortgage</td>
                        <td></td>
                        <td  style="text-align:center"><input type="text" name="octrent" placeholder="0" size="11"></td>
                        </tr>
                        <tr>
                        <td>Electricity Bill</td>
                        <td></td>
                        <td style="text-align:center"><input type="text" name="octelectric" placeholder="0" size="11"></td>
                        </tr>
                        <tr>
                        <td>Water Bill</td>
                        <td></td>
                        <td style="text-align:center"><input  type="text" name="octwater" size="11" placeholder="0"></td>
                        </tr>
                        <tr>
                        <td>Groceries <dfn>(Foodstuffs and various house supplies)</dfn></td>
                        <td></td>
                        <td style="text-align:center"><input  type="text" name="octgrocery" size="11" placeholder="0"></td>
                        </tr>
                        <tr>
                        <td>Internet Service</td>
                        <td></td>
                        <td style="text-align:center"><input  type="text" name="octinternet" size="11" placeholder="0"></td>
                        </tr>
                        <tr>
                        <td>Phone Service</td>
                        <td></td>
                        <td style="text-align:center"><input  type="text" name="octphone" size="11" placeholder="0"></td>
                        </tr>
                        <tr>
                        <td>Cable Service <dfn>(Television)</dfn></td>
                        <td></td>
                        <td style="text-align:center"><input type="text" name="octcable" size="11" placeholder="0"></td>
                        </tr>
                        <tr>
                        <td>Tax</td>
                        <td></td>
                        <td style="text-align:center"><input type="text" name="octtax" size="11" placeholder="0" value="<?php if(isset($_POST['octtax'])){echo htmlentities($_POST['octtax']);} ?>"></td>
                        </tr>
                        <tr>
                        <td>Others</td>
                        <td></td>
                        <td style="text-align:center"><input type="text" name="octhothers" size="11" placeholder="0" value="<?php if(isset($_POST['octhhothers'])){echo htmlentities($_POST['octhothers']);} ?>"></td>
                        </tr>
                    </table>

                <label class="personal">PERSONAL</label>
                    <table class="tpersonal" border="1" rules="none" cellpadding="6px" width="400px">
                        <tr>
                        <th></th>
                        <th></th>
                        <th>RM</th>
                        </tr>
                        <tr>
                        <td>Charity <dfn>(Zakat/Donation etc)</dfn></td>
                        <td></td>
                        <td style="text-align:center"><input  type="text" name="octcharity" size="11" placeholder="0" value="<?php if(isset($_POST['octcharity'])){echo htmlentities($_POST['octcharity']);} ?>"></td>
                        </tr>
                        <tr>
                        <td>Parents</td>
                        <td></td>
                        <td style="text-align:center"><input type="text" name="octparents" size="11" placeholder="0" value="<?php if(isset($_POST['octparents'])){echo htmlentities($_POST['octparents']);} ?>"></td>
                        </tr>
                        <tr>
                        <td>Children</td>
                        <td></td>
                        <td style="text-align:center"><input  type="text" name="octchild" size="11" placeholder="0" value="<?php if(isset($_POST['octchild'])){echo htmlentities($_POST['octchild']);} ?>"></td>
                        </tr>
                        <tr>
                        <td>Travelling</td>
                        <td></td>
                        <td style="text-align:center"><input type="text"  name="octtravel" size="11" placeholder="0" value="<?php if(isset($_POST['octtravel'])){echo htmlentities($_POST['octtravel']);} ?>"></td>
                        </tr>
                        <tr>
                        <td>Shopping <dfn>(Clothes/Shoes etc)</dfn></td>
                        <td></td>
                        <td style="text-align:center"><input  type="text"  name="octshop" size="11" placeholder="0" value="<?php if(isset($_POST['octshop'])){echo htmlentities($_POST['octshop']);} ?>"></td>
                        </tr>
                        <tr>
                        <td>Eating Out</td>
                        <td></td>
                        <td style="text-align:center"><input type="text" name="octeat" size="11" placeholder="0" value="<?php if(isset($_POST['octeat'])){echo htmlentities($_POST['octeat']);} ?>"></td>
                        </tr>
                        <tr>
                        <td>Entertainment <dfn>(Movies/Theme Park)</dfn></td>
                        <td></td>
                        <td style="text-align:center"><input  type="text" name="octentertain" size="11" placeholder="0" value="<?php if(isset($_POST['octentertain'])){echo htmlentities($_POST['octentertain']);} ?>"></td>
                        </tr>
                        <tr>
                        <td>Miscellaneous</td>
                        <td></td>
                        <td style="text-align:center"><input  type="text" name="octmisc" size="11" placeholder="0" value="<?php if(isset($_POST['octmisc'])){echo htmlentities($_POST['octmisc']);} ?>"></td>
                        </tr>
                    </table>

                <label class="transport">TRANSPORTATION</label>
                    <table class="ttransport" border="1" rules="none" cellpadding="6px" width="400px" style="background-color:AntiqueWhite;">
                        <tr>
                        <th></th>
                        <th></th>
                        <th>RM</th>
                        </tr>
                        <tr>
                        <td>Public Transport</td>
                        <td></td>
                        <td style="text-align:center"><input  type="text"  name="octpublic" size="11" placeholder="0" value="<?php if(isset($_POST['octpublic'])){echo htmlentities($_POST['octpublic']);} ?>"></td>
                        </tr>
                        <tr>
                        <td>Car Insurance/Road Tax</td>
                        <td></td>
                        <td style="text-align:center"><input  type="text"  name="octinsurance" size="11" placeholder="0" value="<?php if(isset($_POST['octinsurance'])){echo htmlentities($_POST['octinsurance']);} ?>"></td>
                        </tr>
                        <tr>
                        <td>Car Payment</td>
                        <td></td>
                        <td style="text-align:center"><input  type="text" name="octpay" size="11" placeholder="0" value="<?php if(isset($_POST['octpay'])){echo htmlentities($_POST['octpay']);} ?>"></td>
                        </tr>
                        <tr>
                        <td>Car Servicing</td>
                        <td></td>
                        <td style="text-align:center"><input  type="text" name="octservice" size="11" placeholder="0" value="<?php if(isset($_POST['octservice'])){echo htmlentities($_POST['octservice']);} ?>"></td>
                        </tr>
                        <tr>
                        <td>Petrol</td>
                        <td></td>
                        <td  style="text-align:center"><input  type="text" name="octpetrol" size="11" placeholder="0" value="<?php if(isset($_POST['octpetrol'])){echo htmlentities($_POST['octpetrol']);} ?>"></td>
                        </tr>
                        <tr>
                        <td>Others</td>
                        <td></td>
                        <td style="text-align:center"><input  type="text" name="octtothers" size="11" placeholder="0" value="<?php if(isset($_POST['octtothers'])){echo htmlentities($_POST['octtothers']);} ?>"></td>
                        </tr>
                    </table>
            </div></center>

            <center><input type="submit" class="esave" name="octsave" value="Save"></center>
        </form>
    </div>
 </div></center>

</body>
</html>

thanks in advance and sorry in advance if this seems really noob-ish but yeah that what i am. sorry guys

Recommended Answers

All 12 Replies

Member Avatar for diafol

Well, I can't see what you want. "It's not working!" and you dump 200+ lines of code/markup.
Do we know for example if any of this runs?

if($_SESSION['name']){

Does this test pass? Did you place an

echo "name found";

or similar straight after it? Same goes for all the other "if conditionals"

have you got session_start(); at the top of every page? I assume you must have as you say that it worked until recently and that you "hadn't changed a thing".

Sorry if that sounds a bit stroppy, just trying to narrow down the issues - I'm running low on sugar too :(

BTW, the code could be modified to run in heck of a lot less lines, but we'll come to that again.

you should write it like this :
<?php
session_start();

... the code

?>

session_start();
should be in the first line after <?php
(you can't use sessions unless you write session_start(); in the first line)

my session_start(); is in the income.php as it includes january.php. if i put session_start(); in january.php :

Notice: A session had already been started - ignoring session_start()...line 2

if($_SESSION['name']){ yes this works as i used that line in nearly all the other files and they execute fine. its just this file.

also if i remove session_start() from income.php

<?php if(@$_SESSION['name']) ?><a href="profile.php"><h3><?php echo @$_SESSION['name'] ?></h3></a> this line won't run.

oh btw value="<?php if(isset($_POST['octmisc'])){echo htmlentities($_POST['octmisc']);} ?>" this has been remove.

and as i said i didnt change anything since the last time i touched that piece of file which was last week. also i had to reformat my laptop coz it was jamming up but i backed up everything in regards to my project even the database before reformatting. that wouldnt have disrupted anything right?
i realize there would be an easier way to query what i want but i was just testing things. haven't found a better solution yet, my php and mysql skills are sh-t as im sure you guys have realize. thanks for the input

ok can you test something for me ?
write session_start() in the first line as I said then make the other changes to make the code runs (if it worked then the problem is because of session_start() but if it didn't work it means that the problem is from some where else)

The reason why I'm telling you that session_start() should be in the first line in the file is because it is an condition (not an option)

its the query. its not inserting in the table. well thats what its telling me coz i added

if(!$octhresult)
            {
                echo "something is wrong";
            }

after $octhresult=mysql_query($query);

but my query was executed before. well i guess thats the keyword BEFORE. any ideas? or maybe suggestions to make my query better/work?

oh, then you should write it in this way:
$sql = "INSERT INTO hous(the first field name,the second field name,...etc) VALUES(First value,second value,...etc)";
$query = mysql_query($sql);

nope. that did not work.

can you give me the code that you wrote (the sql and the query) so we can see if there is a problem with it.

Member Avatar for diafol

Sorry to butt in again, but as I see it, the whole form is posted so I can't see the reasoning for the multiple 'if'. It seems that if a single field is left blank, then that table does not get updated. IS that what you wanted?

ive deleted the if statements. i want to insert the datas into tables.

there i changed some. even removing $name=$_SESSION['name'] it still wont insert. and its so frustrating coz i think its smtg really small i missed and its making the whole thing not run.

<?php
session_start();

if($_SESSION['name'])
{
    require "connect.php";

    if(isset($_POST['jansave']))
    {
        $janrent = mysql_real_escape_string($_POST['janrent']);
        $janelectric = mysql_real_escape_string($_POST['janelectric']);
        $janwater = mysql_real_escape_string($_POST['janwater']);
        $jangrocery = mysql_real_escape_string($_POST['jangrocery']);
        $janinternet = mysql_real_escape_string($_POST['janinternet']);
        $janphone = mysql_real_escape_string($_POST['janphone']);
        $jancable = mysql_real_escape_string($_POST['jancable']);
        $jantax = mysql_real_escape_string($_POST['jantax']);
        $janhothers = mysql_real_escape_string($_POST['janhothers']);
        $jancharity = mysql_real_escape_string($_POST['jancharity']);
        $janparents = mysql_real_escape_string($_POST['janparents']);
        $janchild = mysql_real_escape_string($_POST['janchild']);
        $jantravel = mysql_real_escape_string($_POST['jantravel']);
        $janshop = mysql_real_escape_string($_POST['janshop']);
        $janeat = mysql_real_escape_string($_POST['janeat']);
        $janentertain = mysql_real_escape_string($_POST['janentertain']);
        $janmisc = mysql_real_escape_string($_POST['janmisc']);
        $janpublic = mysql_real_escape_string($_POST['janpublic']);
        $janinsurance = mysql_real_escape_string($_POST['janinsurance']);
        $janpay = mysql_real_escape_string($_POST['janpay']);
        $janservice = mysql_real_escape_string($_POST['janservice']);
        $janpetrol = mysql_real_escape_string($_POST['janpetrol']);
        $janmisc = mysql_real_escape_string($_POST['janmisc']);
        $jantothers = mysql_real_escape_string($_POST['jantothers']);


            $janhtotal=$janrent+$janelectric+$janwater+$jangrocery+$janinternet+$janphone+$jancable+$jantax+$janhothers;
            $janptotal=$jancharity+$janparents+$janchild+$jantravel+$janshop+$janeat+$janentertain+$janmisc;
            $janttotal=$janpublic+$janinsurance+$janpay+$janservice+$janpetrol+$jantothers;

            $query1=mysql_query("INSERT INTO house (rent,electric,water,grocery,internet,phone,cable,tax,others,total) VALUES ('$janrent','$janelectric','$janwater','$jangrocery','$janinternet','$janphone','$jancable','$jantax','$janhothers','$janhtotal')");
            if(!$query1)
            {
                echo "nope";
            }


            $query2=mysql_query("INSERT INTO personal (charity,parent,child,travel,shop,eat,entertain,misc,total) VALUES ('$jancharity','$janparents','$janchild','$jantravel','$janshop','$janeat','$janentertain','$janmisc','$janptotal')");
            if(!$query2)
            {
                echo "sorry";
            }

            $query3=mysql_query("INSERT INTO transport (public,insurance,pay,service,petrol,others,total) ('$janpublic','$janinsurance','$janpay','$janservice','$janpetrol','$jantothers','$janttotal')");
            if(!$query3)
            {
                echo "no way";
            }
    }
}
Member Avatar for diafol

This is really not the way to do it. You seem to have loads of variables - different sets for each month. Why can't you just use one set of variables and the same form - just change the month in a single field.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.