Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.