zed420 Posted May 6, 2008 Share Posted May 6, 2008 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>'; } } } Quote Link to comment https://forums.phpfreaks.com/topic/104410-php5-classes/ Share on other sites More sharing options...
wildteen88 Posted May 6, 2008 Share Posted May 6, 2008 You cant just turn a function into a class. Quote Link to comment https://forums.phpfreaks.com/topic/104410-php5-classes/#findComment-534502 Share on other sites More sharing options...
zed420 Posted May 6, 2008 Author Share Posted May 6, 2008 Thanks for the reply Wildteen, if you can ignore the function part for a min. How would I make a class that would link to Database and Insert into database and also how would I display it? Thanks Zed Quote Link to comment https://forums.phpfreaks.com/topic/104410-php5-classes/#findComment-534792 Share on other sites More sharing options...
ablueycolor Posted May 7, 2008 Share Posted May 7, 2008 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>'; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/104410-php5-classes/#findComment-534891 Share on other sites More sharing options...
zed420 Posted May 7, 2008 Author Share Posted May 7, 2008 Thanks ablueycolor, sorry to be a pain but how would display it using select query? Zed Quote Link to comment https://forums.phpfreaks.com/topic/104410-php5-classes/#findComment-535121 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.