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 Link to comment https://forums.phpfreaks.com/topic/92842-can-someone-help-me-figure-out-why-my-code-insert-blank-row-in-mysql/ Share on other sites More sharing options...
Steve Angelis Posted February 25, 2008 Share Posted February 25, 2008 Have it set as 'NULL' Link to comment https://forums.phpfreaks.com/topic/92842-can-someone-help-me-figure-out-why-my-code-insert-blank-row-in-mysql/#findComment-475585 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!! Link to comment https://forums.phpfreaks.com/topic/92842-can-someone-help-me-figure-out-why-my-code-insert-blank-row-in-mysql/#findComment-475589 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? Link to comment https://forums.phpfreaks.com/topic/92842-can-someone-help-me-figure-out-why-my-code-insert-blank-row-in-mysql/#findComment-475593 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 Link to comment https://forums.phpfreaks.com/topic/92842-can-someone-help-me-figure-out-why-my-code-insert-blank-row-in-mysql/#findComment-475597 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 Link to comment https://forums.phpfreaks.com/topic/92842-can-someone-help-me-figure-out-why-my-code-insert-blank-row-in-mysql/#findComment-475600 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!! Link to comment https://forums.phpfreaks.com/topic/92842-can-someone-help-me-figure-out-why-my-code-insert-blank-row-in-mysql/#findComment-475609 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! Link to comment https://forums.phpfreaks.com/topic/92842-can-someone-help-me-figure-out-why-my-code-insert-blank-row-in-mysql/#findComment-475612 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.