function save() { if (!empty($_POST['username']) && !empty($_POST['password'] != '')) { $username = $_POST['username']; $password = $_POST['password']; // Load the CRUD require ROOT . '/justit-php-test/models/crud.php'; $register_user = new Crud(); if (isset($_POST)) { // Start building array $user_data = array('firstname' => $_POST['firstname'], 'lastname' => $_POST['lastname'], 'username' => $_POST['username'], 'password' => md5($_POST['password'])); if ($new_id = $register_user->create($user_data)) { include 'views/register-success.php'; } } } else { // Return back to the login $this->error_message = "Please fill out the form"; $this->index(); } }
<!DOCTYPE HTML> <html> <head> <title>Create Php</title> </head> <body> <?php include_once 'model.php'; if (isset($_POST['submit'])) { $name = $_POST['name']; $address = $_POST['address']; $phone = $_POST['phone']; $gender = $_POST['gender']; $insertData = new Crud(); $insertData->create($name, $address, $phone, $gender); header("Location: read.php"); } ?> <form action="" method="POST"> <div> <label>Name :</label> <input type="text" name="name" /> </div> <div> <label>Address:</label> <input type="text" name="address" /> </div> <div> <label>Phone:</label> <input type="text" name="phone" /> </div>
public function edit($id) { return Crud::create($id); }
/** * Over-rides Crud create * */ public function create() { $this->data['pageKeys'] = $this->_pages->getStorableKeys(); return Crud::create(); }
$codigo = htmlspecialchars($_POST['codigo']); $descripcion = htmlspecialchars($_POST['descripcion']); $categoria = htmlspecialchars($_POST['categoria']); $precio = htmlspecialchars($_POST['precio']); if (!is_numeric($precio)) { $mensaje = "El campo precio deber ser numerico"; } elseif ($codigo == "") { $mensaje = "Error el campo codigo es requerido!"; } elseif ($descripcion == '') { $mensaje = "Error el campo descripcion es requerido"; } else { $model = new Crud(); $model->insertInto = 'Productos'; $model->insertColumns = 'Codigo, Descripcion, Categoria, Precio'; $model->insertValues = "'{$codigo}','{$descripcion}', '{$categoria}', {$precio}"; $model->create(); $mensaje = $model->mensaje; } } ?> <!DOCTYPE html> <html> <head> <meta http-equiv ="content-type" content = "text/html; charset = UTF-8"> </head> <body> <h1>CRUD CREATE: Productos </h1> <strong><?php echo $mensaje; ?> </strong>
/** @expectedException \Exception */ public function test_create() { /** === Call and asserts === */ $this->obj->create([]); }