Announcement

Collapse
No announcement yet.

Requesting help on PHP Programming

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Requesting help on PHP Programming

    Hello, are any game hackers good at php programming?

    I struck on some parts on the php programming

    1)How to use strnatcmp to sort the data in natural ordering when you clicked on the column header link and when you clicked it again, you sort it by ascending order, click one more time back to ascending order.

    2)How to use explode() to make sure that three textboxes can be inserted and can be updated into database. (I mean this format 000|0000-00-00 00:00:00|0)
    | is the delimiter. (for 'dt' fieldname).

    3)How to use checkboxes to update the selected records you have checked, when you clicked on 'Edit' button, it will go go another page where the selected records are displayed and can be edited together. (index.php to multipleupdate.php


    I provided the source file if you can help me.

    I will add reputation points to those who helped me.
    Last edited by silentkiller; 02-03-2012, 09:46:54 PM.
    Keep Smile + Let's be together !! + Magical Glasses + Cowabunga + Superhero + Maximum Carnage

  • #2
    First of all, consider the following. I shortened your code and made it simpler for this section, as well as did the URI stuff a little safer. Really, you should look for specific values, otherwise someone can destroy your database simply by using the URI.

    PHP Code:
    <?php
    require('pagedresults.php'); 
    $sort = (array_key_exists('sort'$_GET)) ? $_GET['sort'] : "tasknm";
    $mode = (array_key_exists('mode'$_GET)) ? $_GET['mode'] : "ASC";


    if (!
    $link mysql_connect('localhost''root''')) die('Could not connect: ' mysql_error());
    if (!
    $db_selected mysql_select_db('1'))  die('Could not select database: ' mysql_error());


    $rs = new MySQLPagedResultSet("SELECT * FROM t1 ORDER BY $sort $mode",2,$link); // display 2 records per page used for pagination


    $mode = ($mode == "ASC") ? "DESC" "ASC";
    ?>
    Now what you should consider about this, is that your mode will be the same for every column. So, when you sort the first by ASC, the rest will go to DESC when clicked. That's not normally how forms work, but it's up to you if you want it that way. I'm not quite sure what you're trying to do here otherwise. If you want a natural sort order by default, you need to omit the order by statement from the query.

    Also, consider this.
    PHP Code:
    <td colspan="9" align="left">
    <input type="button" name="manual"  id="manual" value="Manual Trigger">
    <input type="button" name="btnAdd" value="Add" onClick="parent.location='insertform.php'"> 
    <input type="submit" name="btnDelete" value="Remove">
    <input type="hidden" name="hdnCount" value="<?=$i?>">
    <!--<input type="button" name="btnEdit" value="Edit" id="editbutton" value="Edit">-->
    <input type="button" name="btnMultipleEdit" value="Edit Multiple Records" onClick="parent.location='multipleupdate.php'"> 
    <input type="button" name="btnSearch" value="Search" onClick="parent.location='search.php'"> 
      </td>
    Your Remove button is the only button submitting any POST info. The rest of the buttons are just changing the location without carrying any information with it. There is a way to share inputs between forms so you can have multiple submit buttons for one form's inputs.

    explode() is simple.
    PHP Code:
    $string "000|0000-00-00 00:00:00|0";
    $strings explode("|"$string);
    echo 
    $strings[0]; // 000
    echo $strings[1]; // 000-00-00 00:00:00
    echo $strings[2]; // 0 
    Take that in, then I'll help you with the rest.
    Please put all complaints in writing and submit them here.

    Above link not working? Try here.

    Comment


    • #3
      To add on from rimsky82's post...

      You have lots of places where you aren't escaping user input. It is important that you always escape everything which can be influenced by the user before trying to use it in a query. If you don't then users can inject random SQL fragments in these variables and cause all kinds of trouble.

      You should also move your database connection stuff to a seperate file, eg:

      config.php
      PHP Code:
      <?php

      $objConnect 
      mysql_connect('localhost','root','') or die(mysql_error());
      $objDB mysql_select_db("schdb");

      ?>
      Then, for each of the files that require a database connection just call the following at the top of the page: require_once('config.php');

      This will make it much easier for you to move your PHP application between environments since you will only need to modify the connection information/database name in one file instead of many.

      Lastly I would suggest giving your tables more meaningful names. When you or someone else goes back to update the code are you going to remember what t1, t2, etc. are for?

      Comment


      • #4
        My question is what is the regular expression of 0000-00-00 00:00:00 ?
        Last edited by silentkiller; 02-14-2012, 07:24:29 AM.
        Keep Smile + Let's be together !! + Magical Glasses + Cowabunga + Superhero + Maximum Carnage

        Comment


        • #5
          Hello, I am facing problems of trying to insert exploded values into the database.

          I always get this 000 0000-00-00 00:00:000 format

          For example I type 100 2000-10-02 06:00:10 6 in the three textboxes,

          100 -> textbox 1
          2000-10-02 06:00:10 -> textbox 2
          6 -> textbox 3

          it still remain the same 000 0000-00-00 00:00:000.

          I want to get this data 100|2000-10-02 06:00:10|6 in sql database.

          Can anyone how make it to work?
          Last edited by silentkiller; 07-01-2012, 10:59:47 PM.
          Keep Smile + Let's be together !! + Magical Glasses + Cowabunga + Superhero + Maximum Carnage

          Comment


          • #6
            1) The PHP looks OK for inserting into the table, even though you are exploding the input in insert_ac.php, and then imploding again with string concatenation. (The implode() function would work better.)

            PHP Code:
            $finalstringvalue $ary[0] . "|" $ary[1]  ."|" $ary[2]; 
            ... is equivalent to ...

            PHP Code:
            $finalstringvalue implode('|'$ary); 
            That aside, the code will "work".

            2) insert.php is referencing variables that do not exist.

            3) The JavaScript in insert.php is doing concatenation without the pipe characters. (The result is not used anywhere, however.)

            4) You have three statements in insert_ac.php that are just variables. This is odd.

            5) You don't have any error printing to aid in debugging. mysql_error() could come in handy, for example.

            Comment

            Working...
            X