Jump to content

PHP5 Classes


zed420

Recommended Posts

Hi All

 

I wonder if anyone can help me out I'm fairly new to php, what I am trying to do is, convert this code to PHP5 as in OOP.  How would write this ??? ???

 

include("DB.php");

 

function AddItems(){

if (isset($_POST['submit'])) {

$ItemType= trim($_POST["ItemType"]);

$id= trim($_POST["id"]);

$ItemName= trim ($_POST["ItemName"]);

$ItemDes= trim ($_POST["ItemDes"]);

$ItemPrice= trim ($_POST["ItemPrice"]);

$date= trim ($_POST["date"]);

 

$Query="INSERT into itemtb (ItemType,id,ItemName,ItemDes,ItemPrice,date)

values ('$ItemType','$id','$ItemName','$ItemDes','$ItemPrice','$date')";

if (@mysql_query($Query)) {

echo '<p>Your New Information has been added. This can be seen below.</p>';

DisplayLastOne ();

} else {

echo '<p>Error adding submitted Information: ' .

mysql_error() . '</p>';

}

}

}

 

 

Link to comment
https://forums.phpfreaks.com/topic/104410-php5-classes/
Share on other sites

This is a very crude example. 

 

<?php

include("DB.php");

 

class AddItems {

 

    // default constructor

    function AddItems(){

        $this->ItemType = trim($_POST['ItemType']);

        $this->id = trim($_POST['id']);

        $this->ItemName = trim($_POST['ItemName']);

        $this->ItemDes= trim ($_POST["ItemDes"]);

        $this->ItemPrice= trim ($_POST["ItemPrice"]);

        $this->date= trim ($_POST["date"]);

 

        $this->InsertItems();

    }

 

    function insertItems() {

        $Query="INSERT into itemtb (ItemType,id,ItemName,ItemDes,ItemPrice,date) values ('$this->ItemType','$this->id','$this->ItemName','$this->ItemDes','$this->ItemPrice','$this->date')";

      if (@mysql_query($Query)) {

        echo '<p>Your New Information has been added. This can be seen below.</p>';

        DisplayLastOne ();

        } else {

        echo '<p>Error adding submitted Information: ' .

        mysql_error() . '</p>';

      }

  }

}

?>

Link to comment
https://forums.phpfreaks.com/topic/104410-php5-classes/#findComment-534891
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.