newcircuit.php
Código HTML:
<?php session_start(); if($_SESSION['username'] == true) { echo " <table width='487' border='0'> <tr> <td width='98'></td> <td width='217' align='center'><h2><u>Create a New Circuit</u></h2></td> <td width='79'></td> </tr> <tr> <td><br/></td> <td></td> <td></td> </tr> <form action='newcirc.php' method='post'> <tr> <td>Name circuit:</td> <td><input type='text' name='namecirc' width='300' /></td> <td></td> </tr> <tr> <td> </td> <td> </td> <td></td> </tr> <tr> <td> </td> <td><input type='submit' value='Save Circuit' /></td> <td></td> </tr> <tr> <td><a href='../logout.php'>Log Out</a></td> <td> </td> <td></td> </tr> </form> </table> </center> "; } else { echo "para ver esta pagina debe estar logueado<br/>"; echo"<a href='../login.html'>Login</a>"; }
newcirc.php
Código HTML:
<?php
class circuits
{
public $namecirc;
public $username;
public $query;
public $numrows;
public $error;
public $error2;
public $ok;
public $fields;
public $regquery;
public function __construct($namecirc,$username)
{
include "config.php";
$this->namecirc=$namecirc;
$this->username=$username;
$this->query=mysql_query("SELECT * FROM users WHERE username = '".$this->username."'");
$this->numrows=mysql_num_rows($this->query);
$this->error="Nombre de circuito en uso.";
$this->error2="El nombre de usuario o el nombre del circuito supera los 25 caracteres ";
$this->ok="Has creado un circuito correctamente";
$this->fields="Por favor, rellena todos los campos.";
}
public function check()
{
if($this->numrows!=0)
{
die ($this->error);
}
if($this->namecirc&&$this->username)
{
if(strlen($this->namecirc)>25||strlen($this->username)>25)
{
echo $this->error2;
}
else
{
$register = mysql_query("INSERT INTO circuits(nombreCirc,username) VALUES ('".$this->namecirc."','".$this->username."')");
echo $this->ok;
}
}
else
{
echo $this->fields;
}
}
}
include_once "clear.php";
$reg = new circuits(clear($_POST['namecirc']),clear($_POST['username']) );
echo $reg->check();
?>