Jump to content

Can someone help me figure out why my code insert blank row in MySQL?


ivytony

Recommended Posts

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