//File inserirPF.js
function add(){
var metodo = 'AdicionaPessoa';
$.ajax({
url: "../class/dao/InserirPFDao.class.php",
type: 'POST',
data: {Metodo:metodo, NOME_:NOME, EMAIL_:EMAIL, SENHA_:SENHA},
success: function(data) {
alert(data);
}
});
}
//File InserirPFDao.class.php
<?php
require_once("../class/dao/connection.class.php");
class InserirPFDao extends ConexaoMySQl
{
function __construct(){
parent::Connection();
if (isset($_POST['Metodo'])) {
switch ($_POST('Metodo')) {
case 'AdicionaPessoa':
$retorno = AdicionaPessoa();
mysql_close($db);
echo $retorno;
break;
default:
echo "Nenhum metodo encontrado!"
break;
}
}
}
public function AdicionaPessoa(){
try {
$NOME_ = $_POST("NOME_");
$EMAIL_=$_POST("EMAIL_");
$SENHA_=$_POST("SENHA_");
$Adiciona = mysql_query("INSERT INTO PESSOA (NOME, EMAIL, SENHA)VALUES('".$NOME_."','".$EMAIL_."','".$SENHA_."')");
if($Adiciona)
return true;
else
return false;
}
catch (Exception $e) {
}
}
}
?>
How to call a jQuery arquivoEstou trying to make the connection between Javascript and php with ajax. if anyone knows another way to do ... For showing this to me this error:
<font size='1'>
<table class='xdebug-error xe-parse-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr>
<th align='left' bgcolor='#f57900' colspan="5">
<span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span>
Parse error: syntax error, unexpected T_PUBLIC in C:\Arquivos de programas\VertrigoServ\www\gofinder\class\dao\InserirPFDao.class.php on line
<i>7</i>
</th>
</tr>
</table>
$retorno = AdicionaPessoa();
doesn't look right. I'm guessing you meant:
$retorno = $this->AdicionaPessoa();
And as noted in the comments, you are creating a class but doing nothing with it. You need to instantiate the class. Add the following to the end of your file:
$inserirPFDao = new InserirPFDao();
You might want to have a read of some basic Object Oriented Programming tutorials to help you get started. You look like you are mixing OO and procedural code without understanding the differences.
Have a read through some of these: http://net.tutsplus.com/tutorials/php/object-oriented-php-for-beginners/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.