Ciao ragazzi mi sto avvicinando alle oop con il php , volevo essere consigliato qualche esercizio qualche cosina....
Qualche guida?
Io ho realizzato un guestbook con le oop tanto per....
ora vi posto il codice e mi dite qualche correzzione?
Qualche guida?
Io ho realizzato un guestbook con le oop tanto per....
ora vi posto il codice e mi dite qualche correzzione?
PHP:
<?php
/*
* GusetBook by Vincy6!
*/
/**
*
* @author Vincy6
*/
class db{
var $host="localhost";
var $name="my_*****";
var $user="*****";
var $pass="";
var $connect;
function connect(){
$this->connect=mysql_connect($this->host,$this->user,$this->pass);
if(!$this->connect){
echo'<h3>Errore durante la connessione </h3>Controllare i dati';
exit();
}else{
$this->select();
}
}
function select(){
$select=mysql_select_db($this->name,$this->connect);
if(!$select){
echo
'<h3>Ci sono stati problemi durante la selezione del database';
exit();
}
}
}
class guestbook{
var $nick;
var $testo;
var $data;
var $ora;
var $cap;
function read(){
$query=mysql_query("SELECT * FROM guestbook ORDER BY id DESC");
while($all=mysql_fetch_array($query)){
$nick=$this->nick=$all['nick'];
$nick=htmlentities($nick);
$testo=$this->testo=$all['testo'];
$testo=htmlentities($testo);
$data=$this->data=$all['data'];
$ora=$this->ora=$all['ora'];
echo
'
<div id="commenti">
<div id="in_commenti">
<table border="1" class="table">
<tr>
<td class="nick">'.$nick.'</td>
</tr>
<tr>
<td class="testo"><div class="in_testo"><p>'.$testo.'</p></div></td>
</tr>
<tr>
<td class="data">Questo commento e stato scritto da : '.$nick.' alle ore : '.$ora.' il giorno : '.$data.'</td>
</tr>
</table>
</div>
</div>
';
}
}
function write(){
echo
'
<div id="form">
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
Nick :<br />
<input type="text" name="nick" class="input" />
<br />
Testo:<br />
<textarea name="testo" class="input_text" ></textarea>
<br /><br /> ';
require_once('recaptchalib.php');
$publickey = "6LfWSgcAAAAAAG-4WxY0nfNqknCpA58kBRZtrdN8 ";
$privatekey = "6LfWSgcAAAAAAMhlzW0cwkzyreXMZWWTod0C6-hI";
$resp = "Eseguito";
$error = "Errato,Riprovare.";
if ($_POST["recaptcha_response_field"]) {
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if ($resp->is_valid) {
$this->cap=true;
} else {
$this->cap=false;
$error = $resp->error;
}
}
echo recaptcha_get_html($publickey, $error);
echo'
<br /><br />
<input type="submit" value="Invia" name="invia" class="invia" />
<input type="reset" value="Reset" class="reset" />
</form>
</div>
';
if(isset($_POST['invia'])){
if($this->cap==true)
{
$this->edit($nick=$this->nick=$_POST['nick'],$testo=$this->testo=$_POST['testo']);
if(empty($nick) || empty($testo)){
echo'Compilare tutti i campi. Commento NON inserito.';
$this->read();
}else{
$data=$this->data=date (" d-m-Y ");
$ora=$this->ora=date(" H:i ");
$query=mysql_query("INSERT INTO guestbook (nick,testo,data,ora)VALUE ('$nick', ' $testo', '$data', '$ora')");
if(!$query){
echo"Commento non inserito Correttamente";
}else{
echo'Commento inserito correttamente.Si prega di non aggiornare la pagina se il tuo messaggio non verrà visualizzato.';
}
}
}else{
echo
'Inserire correttamente il capctha';
}
}
}
function edit($nick,$testo){
$nick=trim($nick);
$testo=trim($testo);
$nick=htmlentities($nick);
$testo=htmlentities($testo);
$testo=str_replace("&","&");
$testo=str_replace("\"",""");
}
}
class login{
var $user;
var $pwd;
var $confirm;
var $email;
function registrati(){
echo
'
<div id="form">
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
User :<br />
<input type="text" name="user" class="input" />
<br />
Password :<br />
<input type="text" name="pwd" class="input" />
<br />
Password di Conferma :<br />
<input type="text" name="confirm" class="input" />
<br />
Email :<br />
<input type="text" name="email" class="input" />
<br />
<br /><br />
<input type="submit" value="Invia" name="invia" class="invia" />
<input type="reset" value="Reset" class="reset" />
</form>
</div>
';
if(isset($_POST['submit'])){
$user=$_POST['user'];
$pwd=$_POST['pwd'];
$confirm=$_POST['confirm'];
$email=$_POST['email'];
if(empty($user) || empty($pwd) || empty($confirm) || empty($email)){
echo 'Compilare tutti i campi obbligatori.';
}else{
}
}
}
}