Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP Issue

Options
  • 30-03-2012 5:15pm
    #1
    Registered Users Posts: 377 ✭✭


    I am teaching myself PHP and am having a bit of a problem with something.

    I have created a form and am using that to submit query to the database. The results are going to be posted to a new page. All of this is grand and I have no problems. It all working fine.

    However on the form I want to allow 3 choices of font size say 1-3 and whatever if input the reults are displayed in that font.

    Problem is I cannot get it to work. I used a if /elseif statement but it makes no difference.

    Since the form is very basic I am not using CSS as no need for it so am tearing my hair out trying to figure the font size issue out.
    I can then go on and exepiment with font family, color etc.

    Any tips or advice be very much appreciated.
    Thanks


Comments

  • Registered Users Posts: 806 ✭✭✭Niall09


    Could you paste your code here so we can get a better understanding of it?


  • Registered Users Posts: 377 ✭✭libra02


    Niall09 wrote: »
    Could you paste your code here so we can get a better understanding of it?

    Here is the code for the page results be posted to. I took out the if else statments for the moment in case what I have below is wrong

    [HTML]
    <html>
    <body>

    <table border = "3" cellspacing = "8">
    <caption align = "top">Month: <?php echo $_POST;?></caption>
    <tr>
    <th><i>Order Id</i></th>
    <th><i>Buyers</i></th>
    <th><i>Date of Order</i></th>
    <th><i>Order Item</i></th>
    </tr>



    [PHP]
    <?php
    mysql_connect("localhost", "root", "") or die("Could not connect : " . mysql_error());
    mysql_select_db("purchases")or die("Could not select database");

    $query="select * from purchases o join person c on o.person_id = c.person_id where month(o.order_date) = $_POST[ordermonths]";

    $queryresult = mysql_query($query) or die("Query Error".mysql_error());

    while($purchases = mysql_fetch_array($queryresult, MYSQL_ASSOC)){
    print
    "
    <tr>
    <td>".$purchases."</td>
    <td>".$purchases . " " . $purchases."</td>
    <td>".$purchases."</td>
    <td>".$purchaes."</td>
    </tr>";

    }


    [/PHP]

    </table>
    </body>
    </html>
    [/HTML]


  • Closed Accounts Posts: 3,981 ✭✭✭[-0-]


    libra02 wrote: »
    Here is the code for the page results be posted to. I took out the if else statments for the moment in case what I have below is wrong

    [HTML]
    <html>
    <body>

    <table border = "3" cellspacing = "8">
    <caption align = "top">Month: <?php echo $_POST;?></caption>
    <tr>
    <th><i>Order Id</i></th>
    <th><i>Buyers</i></th>
    <th><i>Date of Order</i></th>
    <th><i>Order Item</i></th>
    </tr>



    [PHP]
    <?php
    mysql_connect("localhost", "root", "") or die("Could not connect : " . mysql_error());
    mysql_select_db("purchases")or die("Could not select database");

    $query="select * from purchases o join person c on o.person_id = c.person_id where month(o.order_date) = $_POST[ordermonths]";

    $queryresult = mysql_query($query) or die("Query Error".mysql_error());

    while($purchases = mysql_fetch_array($queryresult, MYSQL_ASSOC)){
    print
    "
    <tr>
    <td>".$purchases."</td>
    <td>".$purchases . " " . $purchases."</td>
    <td>".$purchases."</td>
    <td>".$purchaes."</td>
    </tr>";

    }


    [/PHP]

    </table>
    </body>
    </html>
    [/HTML]

    Off topic.

    http://www.ibm.com/developerworks/opensource/library/os-php-secure-apps/index.html

    Your code is insecure. You need to validate $_POST[ordermonths].


  • Registered Users Posts: 1,477 ✭✭✭azzeretti


    Just so I get my head around what you are doing:

    Are you giving the user a dropdown option of the font type that the results will be displayed in? If so, you need to post more than one value to the page. You will need to post your query value and also the value of the select-option.

    Unless I am taking you up wrong but I can only see one posted value in the code you posted?


  • Registered Users Posts: 44 damned_junkie


    In the spirit of teaching a man to fish... try putting this at the top of the page you're posting the form to:
    var_dump($_POST);
    

    Then you'll see exactly what's being posted to the page. After that it's a fairly trivial if/else or case statement.

    My guess is that you haven't set value attributes on the option elements in your form.


  • Advertisement
  • Registered Users Posts: 377 ✭✭libra02


    azzeretti wrote: »
    Just so I get my head around what you are doing:

    Are you giving the user a dropdown option of the font type that the results will be displayed in? If so, you need to post more than one value to the page. You will need to post your query value and also the value of the select-option.

    Unless I am taking you up wrong but I can only see one posted value in the code you posted?

    No there is no drop down list for the font size - just asking the user to type in a font size say 1, 2 or 3 and based on whatever number is entered that is the font size the reults will be displayed in.

    Am going to try to do same with number of orders to display as database has 100 enrtry that user enter a number say 30 then 30 purchases be returned.

    Sorry that the problem seems stupid but am teaching myself the very basics before I go on to start an intensive IT course.


  • Registered Users Posts: 377 ✭✭libra02


    Still have been trying things out but nothing happening and it driving me nuts.

    Some tips / advice would be great if anyone willing to pass on some useful advice.

    Thanks


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Did you try damned junkie's suggestion?


  • Registered Users Posts: 6,499 ✭✭✭daymobrew


    libra02 wrote: »
    Still have been trying things out but nothing happening and it driving me nuts.
    Post the html code for the form too.
    And, as Adam says, try damned junkie's suggestion.


  • Moderators, Technology & Internet Moderators Posts: 11,011 Mod ✭✭✭✭yoyo


    Is it that you want an accessibilty font size changer and when the user clicks it then that font size increase/decrease remains across the site? If so JQuery should do the job nicely, look for Jquery text resize with cookies for examples which save the state (in a cookie file),

    Nick


  • Advertisement
  • Registered Users Posts: 377 ✭✭libra02


    Thanks for all the help. I finally figured it out. Some php code in the table and a new variable fixed it all up.


Advertisement