ivytony Posted February 25, 2008 Share Posted February 25, 2008 Here's my code: I created a class called Merchant first: <?php class Merchant { var $id = 0; //this id will be the auto-incremented id in mysql table merchant var $name = ''; var $url = ''; var $domain = ''; function add_merchant() { //this function adds merchant to the mysql table global $db; //$db is a database object, declared elsewhere. $name = $this->name; $url = $this->url; $domain = $this->domain; $sql = "INSERT INTO merchant (name, url, domain) VALUES ('$name', '$url', '$domain')"; $db->query($sql); //$db is a database object, declared somewhere } } ?> Below is to get the input submitted from a form: <?php //in a different page than the above class and function codes $merchantres = new Merchant; //new object of Merchant $merchantres->name = strip_tags(trim($_POST['name'])); $merchantres->url = strip_tags(trim($_POST['url'])); $merchantres->domain = strip_tags(trim($_POST['domain'])); $merchantres->add_merchant(); //call the function add_merchant to save the data. ?> After I typed in something in the form and submitted it, I got a blank row insert: nothing but the auto-incremented id. I am wondering what is wrong with my code. Can someone here help me figure out?? I appreciate your reply Quote Link to comment Share on other sites More sharing options...
Steve Angelis Posted February 25, 2008 Share Posted February 25, 2008 Have it set as 'NULL' Quote Link to comment Share on other sites More sharing options...
ivytony Posted February 25, 2008 Author Share Posted February 25, 2008 I'm sorry, which var should I set to 'NULL'? or the column in the mysql table? thanks!! Quote Link to comment Share on other sites More sharing options...
Steve Angelis Posted February 25, 2008 Share Posted February 25, 2008 Wait are you trying to insert a blank row or the database is showing up with nothing being inserted? Quote Link to comment Share on other sites More sharing options...
ivytony Posted February 25, 2008 Author Share Posted February 25, 2008 nothing being inserted, but the ID (primary key, auto-incremented) increases by 1 when I call the add_merchant function after submit form data. I am trying to insert the submitted form data: name, url, and domain. thanks Quote Link to comment Share on other sites More sharing options...
Steve Angelis Posted February 25, 2008 Share Posted February 25, 2008 echo ever $_POST at the beginning, see if they show up Quote Link to comment Share on other sites More sharing options...
ivytony Posted February 25, 2008 Author Share Posted February 25, 2008 now it works. I just found I should use $_GET to get my form data. sorry about that thanks!! Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 25, 2008 Share Posted February 25, 2008 Actually, you should use post - change your form's method to post! Quote Link to comment 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.