More efficent content management?

Discussion in 'PHP' started by X.Homer.X, May 23, 2008.

  1. #1
    I'm coding a website for a gaming clan, and I was wondering. Is there a more efficient way to enter data into and update tables than I am using? I thought about it a bit more, and figured there aught to be a better way.

    How I have it working now, is on my admin panel, you can add members, contacts etc. and each goes to a PHP page with a form on it. Once the data is entered, it is sent to a separate file to insert into the database. For example,

    You enter data into a form (e.g. new clan announcement) -- newannounce.php

    The data is sent to an insert script page. -- insert_announce.php

    Data is inserted to database.

    Each time you add something, there is a separate page with the same code except for the table name and table rows. So i end up having multiple files.

    newmember.php
    newarticle.php
    newcontact.php
    newserver.php
    insert_member.php
    insert_article.php
    insert_contact.php
    insert_server.php

    The same goes for updating, I also have four files to update each section.

    update_member.php
    update_article.php
    update_contact.php
    update_server.php

    Each of these changes the name, or content of what is already entered in the database. The problem here is not with MySQL, but with the amount of PHP files used to edit and enter data into them. Also, the pages i have work fine as they are, I am just wondering, is there any way to do this process more efficiently?
     
    X.Homer.X, May 23, 2008 IP
  2. X.Homer.X

    X.Homer.X Peon

    Messages:
    290
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    X.Homer.X, May 24, 2008 IP
  3. Kalyse

    Kalyse Peon

    Messages:
    1,221
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Having multiple files isn't a problem.
    Having multiple files could in fact be more effecient for your server because even though its not executing code, it still has to scan the files. Its all about programming styles.

    When Im coding OOP you might find that you have lots of different files.
    I wouldn't however separate the files in the way you have done them, I would keep all the different inserts in a single file (or even the same one since they aren't going to be used elsewhere theres no reason to split them up).

    Just keep them in the main announce.php file.
    Show some code you have
     
    Kalyse, May 24, 2008 IP
  4. itnashvilleCOM

    itnashvilleCOM Banned

    Messages:
    176
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #4
    As long as you keep the mysql queries only running when needed and such, you are fine. Object orientation is definitely a must these days.
     
    itnashvilleCOM, May 25, 2008 IP
  5. X.Homer.X

    X.Homer.X Peon

    Messages:
    290
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    See, im including a few files for each page, so my insert_article.php would be like
    
    <?php include('includes/top.php') ?>
    <?php include(includes/'insert_article.php') ?> // a file in includes with the same name which executes code.
    <?php include('includes/bottom.php') ?>
    
    Code (markup):
    my insert_article.php file would look like this

    
    <div id="content">
    	    <div class="news">
    	      <div class="news_title"><h3> &raquo; Add a news article.</h3></div>
    	      <p class="content">
    <?php
    $con = mysql_connect("*********","*********","*********");
      if (!$con)
        {
        die('Could not connect: ' . mysql_error());
        }
    
      mysql_select_db("*********", $con);
    if ($username=="W3C [Validator]")
      {
      echo 'Dont make an article, because its just a validator';
      }
    else
      {
      $sql="INSERT INTO articles (article_title, article_sub, article_content, article_author, article_date)
      VALUES
      ('$_POST[title]','$_POST[subtitle]','$_POST[article]','$username',CURDATE())";
    
      if (!mysql_query($sql,$con))
        {
        die('Error: ' . mysql_error());
        }
      echo "A new article has been added!";
      }
      mysql_close($con)
    ?>
    <br><br><br><a href="/admin">Go back to Admin Panel</a>
    </p>
    	    </div>
    	  </div>
    
    Code (markup):
    how would reccomend doing this (im not really a pro at php right now, hoping to learn more. im only 14, so i have lots of time. :p)
     
    X.Homer.X, May 25, 2008 IP
  6. itnashvilleCOM

    itnashvilleCOM Banned

    Messages:
    176
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #6
    1. Don't include the database connection and authentication int he same script. [security]
    2. Do not just insert the data into the database. You will be hacked. Validate and backslash first. [security]
    3. Why would the W3C validator be submitting to your form parsing script?
    4. Make sure that each variable is not empty, unless you want an article with no title for example.
     
    itnashvilleCOM, May 27, 2008 IP
  7. shecodes

    shecodes Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Since you're doing quite a bit of heavy lifting with PHP, I'd be more inclined to use something like http://codeigniter.com/
     
    shecodes, May 27, 2008 IP
  8. X.Homer.X

    X.Homer.X Peon

    Messages:
    290
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    @itnashvilleCOM

    i dont know how to do any of what you said. im new to php, what do you mean, authenticate and connect in different scripts?, i dont know what you mean by validate and backslash,

    w3c uses my form because i use my forum's database for my users. and W3C Validator is a user on the forum (bot) and it logs in.

    and i dont care if i have empty variables, if something is empty, i can always edit it.

    @shecodes

    what is codeigniter for? i dont want something to make m y scripts for me, because i want to learn php.
     
    X.Homer.X, May 28, 2008 IP
  9. X.Homer.X

    X.Homer.X Peon

    Messages:
    290
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    itnashvilleCOM can you explain yourself better for a noobie? authenticate and connect ins in different scripts? such as check if the user is a user in a different script as my connection info. so instead of having $con = blah blah blah

    have <?php include('connect.php') ?>

    Also, what do you mean by validate and backslash, ive searched on google and cant find out what that is or how to do it.

    if anyone can help me out with either of these problems, please do.
     
    X.Homer.X, May 30, 2008 IP