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...
So when I do...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"; }
$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.
There's obviously something simple that I'm missing or I'm just not fully understanding classes. Can someone help me out?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" } }
Try changing:
toCode:mysql_select_db($this->database, $con);
and see if that produces an error.Code:mysql_select_db($this->database, $con) or die(mysql_error());
Hey, thanks for taking a look. I changed the command and it didn't produce any errors.
Does anyone have any idea what is wrong with this?
What is not working about it right now?
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks