Skip to content

Instantly share code, notes, and snippets.

@twhittakerdev
Last active December 15, 2015 07:09
Show Gist options
  • Save twhittakerdev/5221340 to your computer and use it in GitHub Desktop.
Save twhittakerdev/5221340 to your computer and use it in GitHub Desktop.
PHP Mysql CRUD simple application. Part 1
<?php
// Replace the variable values below
// with your specific database information.
$host="localhost";
$user="root";
$pass="";
$db="olexam";
$con=mysql_pconnect($host,$user,$pass);
if(!$con){
echo "sorry cnt connect to db";
} else{
mysql_select_db($db);
}
?>
/* copy of the database*/
CREATE DATABASE registration;
use registration;
CREATE TABLE `registration` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR( 30 ) NOT NULL ,
`email` VARCHAR( 30 ) NOT NULL ,
`fname` VARCHAR( 30 ) NOT NULL ,
`lname` VARCHAR( 30 ) NOT NULL
) ENGINE = INNODB;
<!DOCTYPE html>
<html>
<head> <title>Registration Form Tuts by S.C.U</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body><!-- -->
<header id="head"> <!-- header tag -->
<p> save information to mysql Tutorial # beginners tutorial </p>
</header><!-- end header tag-->
<?php require_once 'connect.php'; //here we call our connect.php page to connect to the databae
?>
<?php
if(isset($_POST['submit'])){
$username=mysql_real_escape_string($_POST['username']);
$email=mysql_real_escape_string($_POST['email']);
$lname=mysql_real_escape_string($_POST['lname']);
$fname=mysql_real_escape_string($_POST['fname']);
$query = "INSERT INTO registration(`username`,`email`,`fname`,`lname`)
VALUES('$username','$email','$fname','$lname') ";
$sql = mysql_query($query);
echo"<p> Inserted successfully : )</p>";
echo "go <a href=\"index.php\"> back </a>";
exit;
}//end if
?>
<div id="main-wrapper">
<div id="login-wrapper">
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
<ul>
<li>
<label for="usn">Username: </label>
<input type="text" maxlength="30" required autofocus name="username" />
</li>
<li>
<label for="usn">Email : </label>
<input type="email" maxlength="30" required autofocus name="email" />
</li>
<li>
<label for="usn">First Name : </label>
<input type="text" maxlength="30" required autofocus name="fname" />
</li>
<li>
<label for="usn">Last name: </label>
<input type="text" maxlength="30" required autofocus name="lname" />
</li>
<li>
<li class="buttons">
<input type="submit" name="submit" value="Save" />
</li>
</ul>
</div> <!--end login wrapper -->
</div><!-- end main wrapper-->
</body>
</html>
body { line-height: 1; }
ol, ul { list-style: none; }
blockquote, q { quotes: none; }
blockquote:before, blockquote:after, q:before, q:after { content: ''; content: none; }
table { border-collapse: collapse; border-spacing: 0; }
/* Styling the Header */
header#head { background-color:#706f6f; height: 50px; width: 100%; }
header#head p { font-family: georgia, Helvetica, sans-serif; font-size: 17px; color:white; font-weight: bold; padding: 20px; }
header#head p #register { float: right; margin-top: -60px; }
header#head p a:hover #register { color:#999; }
/* Styling the main wrapper */
#main-wrapper { width: 100%; height: 100%; }
/* Styling the login wrapper */
#login-wrapper { margin: 0px auto; width: 310px; height: 290px;
padding: 50px 1px 10px 50px;
margin-top: 150px;
-moz-box-shadow: 0px 0px 10px #888;
-o-box-shadow: 0px 0px 10px #888;
-webkit-box-shadow: 0px 0px 10px #888;
-moz-border-radius: 10px 10px 10px 10px;
-o-border-radius: 10px 10px 10px 10px; -webkit-border-radius: 10px 10px 10px 10px; }
#register-wrapper { margin: 0px auto; width: 310px; height: 250px; padding: 50px 1px 10px 50px; margin-top: 150px; -moz-box-shadow: 0px 0px 10px #888; -o-box-shadow: 0px 0px 10px #888; -webkit-box-shadow: 0px 0px 10px #888; -moz-border-radius: 10px 10px 10px 10px; -o-border-radius: 10px 10px 10px 10px; -webkit-border-radius: 10px 10px 10px 10px; }
/* Form height, margin, padding */ form ul { list-style: none; margin: 0; padding: 0; }
form ul li { margin: .9em 0 0 0; padding: 0; } form * { line-height: 1em; }
/* field labels */
label { clear: left; text-align: right; width: 15%; font-family: arial; font-weight: bold;
font-size: 15px; color: #808080; }
/* the fields */
input { font-size: .9em; }
input { border: 2px solid #666; -moz-border-radius: 5px;
-webkit-border-radius: 5px; border-radius: 5px;
background: #fff; }
input { display: block; margin: 0; padding: .4em; width: 80%; }
/* Place a border around focused fields */
form *:focus { border: 2px solid #7c412b; outline: none; }
/* Display correctly filled-in fields with a green background */
input:valid { background: #efe; }
/* Submit buttons */
.buttons { text-align: center; margin: 20px 0 0 -80px; }
input[type="submit"], input[type="button"] { display: inline; margin: 0 5px;
margin-left:20px; width: 10em; padding: 10px; border: 2px solid #7c412b;
-moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px;
-moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8);
-webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); box-shadow: 0 0 .5em rgba(0, 0, 0, .8); color: #fff; background: #ca5f34; font-weight: bold; -webkit-appearance: none; } input[type="submit"]:hover, input[type="submit"]:active, input[type="button"]:hover, input[type="button"]:active { cursor: pointer; background: #fff; color: #ef7d50; }
input[type="button"]:active, input[type="button"]:active { background: #eee; -moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8) inset; -webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8) inset; box-shadow: 0 0 .5em rgba(0, 0, 0, .8) inset; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment