Jump to content

Having problems with classes

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
eulogy

eulogy

    Newbie

  • Members
  • Pip
  • 6 posts
Basically what I'm trying to do is insert data into a database. I know how to do this fine, but I'm trying to do it with classes and I'm running into a lot of problems. And I just don't know what I'm doing wrong.

I made a class for another site I was playing around with that would echo the information in a database and what worked fine.

But here is my deal...

class echoME{
	var $host = localhost;
	var $login = "login";
	var $pass = "pass";
	var $database = "db";


	function insert($name, $url, $perma) {

		//Action - 0 = INSERT, 1 = Delete, 
		$con = mysql_connect($this->host, $this->login, $this->pass);
		if (!$con) { die('Could not connect: ' . mysql_error()); }
		mysql_select_db($this->database, $con);	
		echo "connected";
}

So when I do...

$variable = new echoME;
echo $variable->insert("test", "xxx.yyyyyy.zzz", "my-test");

The output will produce "connected".

But when I add the insert commands, I get nothing.

	function insert($action, $name, $url, $perma) {

		//Action - 0 = INSERT, 1 = Delete, 
		$con = mysql_connect($this->host, $this->login, $this->pass);
		if (!$con) { die('Could not connect: ' . mysql_error()); }
		mysql_select_db($this->database, $con);	
		echo "connected";
		
		
		$d = date('d');
		$sql = "INSERT INTO links (Name, URL, Perma, Dcount, Ycount, Tcount, Dstamp)
		VALUES ('$name', '$url', '$perma', 0, 0, 0, '$d')";
		if (!mysql_query($sql, $con)) { die('Error: ' . mysql_error()); }
		echo "Added"

		}
		
	
	}

There's obviously something simple that I'm missing or I'm just not fully understanding classes. Can someone help me out?

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Try changing:

mysql_select_db($this->database, $con);	
to
mysql_select_db($this->database, $con) or die(mysql_error());
and see if that produces an error.

#3
eulogy

eulogy

    Newbie

  • Members
  • Pip
  • 6 posts
Hey, thanks for taking a look. I changed the command and it didn't produce any errors.

#4
eulogy

eulogy

    Newbie

  • Members
  • Pip
  • 6 posts
Does anyone have any idea what is wrong with this?

#5
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
What is not working about it right now?

#6
eulogy

eulogy

    Newbie

  • Members
  • Pip
  • 6 posts
I just get a blank white screen. Nothing echos.

Like if you look at the two boxes of code, the first box works fine, but when I add in the stuff after it doesn't produce any results.