0

i am updating the form of use and i get id from another page how can i user this id in class and function of class . i am doing this

public function edit_vender()
{
        $sqlupdate = "UPDATE `vender_master` SET `vender_no`='$this->vender_no',`vender_title`='$this->vender_title',`vender_address`='$this->vender_address',`vender_telephone`='$this->vender_telephone',`vender_email`='$this->vender_email',`vender_name`='$this->vender_name',`vender_cell`='$this->vender_cell',`vender_comments`='$this->vender_comments',`bank_name`='$this->bank_name',`bank_code`='$this->bank_code',`account_no`='$this->account_no',`account_holder`='$this->account_holder',`contactperson_name`='$this->contactperson_name',`contactperson_designation`='$this->contactperson_designation',`contactperson_cell`='$this->contactperson_cell',`contactperson_department`='$this->contactperson_department',`contactperson_telephone`='$this->contactperson_telephone',`contactperson_email`='$this->contactperson_email' WHERE `vender_id` ='$this->vender_id'";


    $result = @mysql_query($sqlupdate, $this->get_conn());
    if(!$result)
    {
        throw new Exception("Failed To Inser Query" . mysql_error());
    }   
}

i have send id to process file from input hidden input but how can i send this to the class

  • How and where is `edit_vender()` called? From where does an ID come from? This question is missing context. Also, your table is _huge_, consider separating it into multiple tables. For starters, consider storing your information about vendors and contact persons in separate tables. – ljacqu Jul 19 '14 at 08:34
  • i called edi_vender() in process file and and question is that how can i use this specific user id in class of vender. –  Jul 19 '14 at 08:45

1 Answers1

0

It's hard to give a specific answer to your problem, but I'll try my best to answer your question after mentioning a few other concerns you should look into.

SQL code in PHP

Be sure not to use the deprecated MySQL functions in PHP – as explained in _Why shouldn't I use mysql__* functions in PHP?.

Whenever you insert variables into SQL code, consider using prepared statements rather than directly putting them into the code. These functions were designed to add data into SQL code in a safe way.

Database Design

You are using one table with tons of rows. This isn't handy as you have tons of fields to always take care of, even if you're just interested in vendor information, for instance. For starters, consider storing your information about vendors and contact persons in separate tables.

Getting external ID

i am updating the form of use and i get id from another page how can i user this id in class and function of class

It is clear that your function edit_vender() is inside a class, so I assume you have some ID you want to pass to this class? You could use a parameter inside your function to pass it along externally:

public function edit_vender($id) {
    $sqlupdate = 'UPDATE `vender_master` SET `vender_no` = ?';
    // PDO style example where $dbh is a PDO object
    $dbh->prepare($sqlupdate);
    $dbh->execute( array($id) );
}

So wherever you're calling edit_vender() from, you can just pass the ID you want and do whatever you want with it. If you want to do a lot with the ID, you could save it into the class. Say you have something like:

class MyClass {
    private $id;

    function __construct($id) {
        $this->id = $id;
    }
}

// Pass an ID to the class
$myObj = new MyClass(123);
Community
  • 1
  • 1
ljacqu
  • 2,132
  • 1
  • 17
  • 21