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 ;)

 

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

 

 

Archived

This topic is now archived and is closed to further replies.

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