Jump to content


a php class error


6 replies to this topic

#1 ap_

    Young Padawan

  • Members
  • Pip
  • 31 posts

Posted 15 December 2007 - 11:41 AM

i'm new on php oop and im makin a class

<?PHP

class users{

var id;
var name;
var lastnm;
var location;
var nick;
var contact;
var password;
var retypeps;


function dbinstert($val[0],$val[1],$val[2],$val[3],$val[4],$val[5],$val[6],$val[7]){
 this->id = $id;
 this->name = $name;
 this->lastnm = $lastnm;
 this->location = $location;
 this->nick = $nick;
 this->contact = $mail;
 this->web = $web;
 this->password = $pass;
 
$query = "insert into table test values(null,'$name','$lastnm','$location','$nick','$pass'";
$result = mysql_query($query) or die(mysql_error());
 
if($result != true){
 return false;
}else{
 return true;
}

mysql_close($result);

}

function chekus(this->nick = $nick){
 $chek = mysql_query("select nick from test where nick='$nick'") or die(mysql_error());
 
if($chek !=0){
 return = 0;
}else{
 return 1;
}

mysql_close($chek);

}

function ckmail($this->contact = $mail){
//validation
}

function ckpass($this->password = $pass , $retypeps->$retype){

if($pass != $retype){
 return 0;
}else{
 return 1;
}

}


}

?>


in get this error


Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in xxx\htdocs\fd\users.class on line 5

little help here?

thanks by the way!

#2 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 15 December 2007 - 11:55 AM

Hi,

hm, I never used the word 'var' in PHP but I do know when adressing variables, use $

so:

private $id;
private $name;
private $lastnm;
private $location;
private $nick;
private $contact;
private $password;
private $retypeps;

also don't forget it when using the $this pointer
so for example:
$this->myFunction();


Another tip when working in OOP, make your inner class-variables private (see my example) and use functions to retrieve their values rather then the var itself when adressing your object from other classes.

#3 ap_

    Young Padawan

  • Members
  • Pip
  • 31 posts

Posted 15 December 2007 - 12:28 PM

I found what its was but thanks by the way!

but im wondering whats the diference between the var and private?

im working in a proyect wanna team up? :)

Edited by ap_, 15 December 2007 - 12:59 PM.


#4 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 15 December 2007 - 12:47 PM

http://php.net/oop <-- PHP = 4 OOP
http://php.net/manual/en/language.oop5.php <-- PHP = 5 OOP

http://php.net/manual/en/language.oop5.visibility.php <-- PHP 5 class variable visibility.

Bookmark php.net, it'll save you a lot of headaches :)

In regards to making variable's private though, keep in mind that it is an industry recommendend standard for some stupid reason. Yes, i understand the reason, but i still find private variables to be more trouble than they are worth. If you are a beginner programmer, i highly recommend not even worrying about what the difference is until you get an understanding of the basics first.

Edited by rc69, 15 December 2007 - 12:50 PM.


#5 ap_

    Young Padawan

  • Members
  • Pip
  • 31 posts

Posted 15 December 2007 - 05:42 PM

jeje sorry for bothering so much but im not to used to deal with php clases

i have this form
<?php

mysql_connect("xxx.xxx.xxx.xxx","xxxx","xxxx") or die(mysql_error());
mysql_select_db('test') or die(mysql_error());


function form($enable){

if($enable != 0){

echo('<form method="post">
<input type="hidden" name="id" value="[b]id[/b]" /><br />
name<input type="text" name="name" /><br />
last name<input type="text" name="lastnm" /><br />
location <input type="text" name="location" /><br />
nick <input type="text" name="nick" /><br />
contact <input type="text" name="contact" /><br />
pass <input type="text" name="password" /><br />
retype pass <input type="text" name="retypeps" /><br />
<input type="submit" name="reg" value="Enviar" />
<input type="reset" value="Reintentar" />
</form>');

}else{

echo('Disabled!');

}

}

if(!isset($_POST['reg'])){

echo form(1);

}else{

include('users.class');

$do = new users;

$nm = $_POST['name'];
$lsnm = $_POST['lastnm'];
$lon = $_POST['location'];
$nk = $_POST['nick'];
$cont = $_POST['contact'];
$pass = $_POST['password'];
$repass = $_POST['retypeps'];

if($do->ckpass($pass,$repass) == 0){

echo('password error!');
exit();

}else{

$do->dbinsert(null,'$nm','$lsnm','$lon','$nk','$pass','$cont','$web');

if($do->dbinsert() !== true){

echo('error!');

}else{

echo('done!');

}




}

}

Fatal error: Call to undefined method users::dbinsert() in xxxx\htdocs\fd\test.php on line 57

when submited show this error !

little help :)

thnks by the way!

Edited by ap_, 18 December 2007 - 07:40 PM.


#6 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 16 December 2007 - 04:08 AM

You are trying to call a function within the class users that hasn't been found, so either the name is wrong (more likely) or you havn't made it yet.

Matt

#7 ap_

    Young Padawan

  • Members
  • Pip
  • 31 posts

Posted 16 December 2007 - 04:04 PM

thanks!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users