Closed Thread
Results 1 to 6 of 6

Thread: Having problems with classes

  1. #1
    eulogy is offline Newbie
    Join Date
    May 2009
    Posts
    6
    Rep Power
    0

    Having problems with classes

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

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

    Code:
    	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. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    Re: Having problems with classes

    Try changing:

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

  4. #3
    eulogy is offline Newbie
    Join Date
    May 2009
    Posts
    6
    Rep Power
    0

    Re: Having problems with classes

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

  5. #4
    eulogy is offline Newbie
    Join Date
    May 2009
    Posts
    6
    Rep Power
    0

    Re: Having problems with classes

    Does anyone have any idea what is wrong with this?

  6. #5
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    Re: Having problems with classes

    What is not working about it right now?

  7. #6
    eulogy is offline Newbie
    Join Date
    May 2009
    Posts
    6
    Rep Power
    0

    Re: Having problems with classes

    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.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 13
    Last Post: 09-09-2011, 09:18 PM
  2. C++ classes
    By bgjyd834 in forum C and C++
    Replies: 1
    Last Post: 04-26-2011, 06:43 AM
  3. Problems passing an object through private classes
    By 9erNumber16 in forum Java Help
    Replies: 1
    Last Post: 02-26-2011, 12:30 AM
  4. Problems while using an array of classes
    By Graham-lol in forum C# Programming
    Replies: 2
    Last Post: 12-18-2010, 12:46 PM
  5. Classes
    By sthenri in forum Java Help
    Replies: 2
    Last Post: 12-06-2007, 05:16 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts