How do I do an insert to mysql on the onsubmit using object oriented coding?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • E Pera

    #1

    How do I do an insert to mysql on the onsubmit using object oriented coding?

    I am trying to use more object oriented code with PHP. I am trying to add a record to a table with the submit button, but I do I do it? I need some direction. This is not working. Thanks!

    Code:
    <form id="CMSAdd" name="CMSAdd" onsubmit="<? php $addCMSRecord = new GetCMSRecord();$addCMSRecord -> save_AddRecord(); ?>" method= $_REQUEST > 
    
    
    if (document.CMSAdd.R1.value == "ENewsletter" ) {
      /*** sql to INSERT a new record ***/
       $sql = "INSERT INTO enewsletter (enews_year,   enews_month, enews_title, enews_path, enews_edition)
        VALUES ( CMSAdd.txtEYear.value, CMSAdd.optEMonth.value, CMSAdd.txtETitle.value, CMSAdd.txtELink.value, CMSAdd.optEEdition.value) or die('Couldn't insert data from eNewsletter table: '.mysql_error())";
    
       return $sql;
    }
    Last edited by Markus; Oct 7 '10, 07:19 PM. Reason: Added [code] tags
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    That is not valid PHP code. I don't understand the problem, either.

    Comment

    • dlite922
      Recognized Expert Top Contributor
      • Dec 2007
      • 1586

      #3
      Start off by separating your HTML from you PHP code. Use a templating system like Smarty.

      Then create classes for each of your uses. For example it would be useful for you to create a class that handles database interactions. This class would be used for everywhere in your program you need to access the DB.

      Further more you could have classes for each of your objects. If you're program deals with students, you could have a students class that stores student information.

      But most importantly of all, OOP and PHP have nothing to do with HTML. HTML cannot be OOP because it's not a programming language, it's a markup language. HTML = HyperText Markup Language"

      Cheers Mate,


      Dan
      Last edited by Dormilich; Oct 8 '10, 05:35 AM. Reason: corrected explanation

      Comment

      Working...