Last active
February 8, 2016 07:13
-
-
Save pdrolima/cc427c4a455815bc959c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* @author Pedro | |
*/ | |
$host = "localhost"; | |
$user = "root"; | |
$pass = ""; | |
$banco = "gc"; | |
$conexao = mysql_connect($host, $user, $pass) or die(mysql_error()); | |
mysql_select_db($banco) or die(mysql_error()); | |
// Você definir um atributo 'name="login"' no formulário e ao invés de verificar $_POST possui dados, | |
// Você usuaria (if(isset($_POST['login'])) { # código. .. } | |
if (count($_POST) > 0) { | |
$login = $_POST['login']; | |
$senha = md5($_POST['senha']); // Você não precisa informar ao usuário que a senha dela é em MD5, isso é visto com um termo técnico, ou seja, desncessário. | |
$nickname = $_POST['nickname']; | |
$GP = $_POST['GP']; | |
$VP = $_POST['VP']; | |
$DPOINTS = $_POST['DPOINTS']; | |
$sql = mysql_query("INSERT INTO users(login, senha, nickname, GP, VP, DPOINTS) | |
VALUES('$login', '$senha', '$nickname', '$GP', '$VP', '$DPOINTS')"); | |
// Se os dados foram inseridos vamos imprimir uma mensagem para o usuário | |
// O operador ternário: http://pt.stackoverflow.com/a/56814 | |
echo ($sql === true) ? "Cadastro realizado com successo! <br> " : "Ocorreu um erro ao cadastrar seus dados!"; | |
} | |
/* | |
Navicat MySQL Data Transfer | |
Source Server : localhost_3306 | |
Source Server Version : 100109 | |
Source Host : localhost:3306 | |
Source Database : gc | |
Target Server Type : MYSQL | |
Target Server Version : 100109 | |
File Encoding : 65001 | |
Date: 2016-02-08 05:12:24 | |
*/ | |
/* | |
SET FOREIGN_KEY_CHECKS=0; | |
-- ---------------------------- | |
-- Table structure for users | |
-- ---------------------------- | |
DROP TABLE IF EXISTS `users`; | |
CREATE TABLE `users` ( | |
`ID` int(11) NOT NULL AUTO_INCREMENT, | |
`login` varchar(32) DEFAULT NULL, | |
`senha` varchar(255) DEFAULT NULL, | |
`nickname` varchar(64) DEFAULT NULL, | |
`GP` int(11) DEFAULT NULL, | |
`VP` int(11) DEFAULT NULL, | |
`DPOINTS` int(11) DEFAULT NULL, | |
PRIMARY KEY (`ID`) | |
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; | |
*/ | |
?> | |
<!-- O atributo name="" na tag <form> é similar ao atributo ID em botões, inputs, etc.. Você não precisa usá-lo. --> | |
<form method="post" action=""> | |
Login: <Input type="text" name="login" /><br /><br /> | |
Senha: <input type="password" name="senha" /><br /><br /> | |
Nickname: <input type="text" name="nickname" /><br /><br /> | |
GP: <input type="text" name="GP" /><br /><br /> | |
VP: <input type="text" name="VP" /><br /><br /> | |
DPoints: <input type="text" name="DPOINTS" /><br /><br /> | |
<input type="submit" value="Criar" /><br /><br /> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment