Expand|Select|Wrap|Line Numbers
- <?php
- include 'validate.php';
- include 'connection.php';
- include 'formclass.php';
- ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Register Here...</title> <style type="text/css">
- .table {
- width: auto;
- margin-top: 100px;
- }
- .body {
- background-image:url("http://bytes.com/images/background.jpeg"); background-repeat: repeat-x;background-repeat: repeat-y;
- }
- .errorMsg{border:1px solid red; }
- </style> </head> <body class="body"> <fieldset style="margin-left: 500px; margin-right: 500px; margin-top: 90px"> <legend><img src="http://bytes.com/images/reg.jpg" width="150px"></legend> <table align="center" class="table"> <?=$error?> <?php
- $form = new Form();
- echo $form->create(array('id'=>'registration','name'=>'registration','method'=>'post','action'=>'newreg.php'));
- ?> <tr> <td><?php $label= new form;
- echo $label->label1(). "Username";
- ?> </td> <td> <?php $textbox= new form;
- $par = array(
- array(
- 'name'=>'name11',
- 'value'=>$username,
- 'id'=>'name',
- 'maxlength'=>'50'
- ));
- echo $textbox->text($par);
- ?> </td> <td><?=$error1?> </td> </tr> <tr><td>
- Email :</td><td><input type="text" name="email" value="<?=@$email ?>" maxlength="100" /></td><td> </td></tr> <tr><td>
- password:</td><td><input type="password" name="password" value="<?=@$password?>" maxlength="32"/></td><td></td></tr> <tr><td>
- Re-password:</td><td><input type="password" name="repassword" value="<?=@$password1?>" maxlength="32"/></td><td></td></tr> <tr><td></td><td><input type="submit" name="submit" value="Submit"/></td><td></td> </tr> </FIELDSET> </table> <?php echo $form->close(); ?> <?php
- // if (isset($_POST['submit']) && $error == '') { // if there is no error, then process further
- // echo "<p class='success'>Form has been submitted successfully.</p>"; // showing success message
- // hashing the password and sanitize data
- // $_POST['password'] = md5($_POST['password']);
- // foreach ($_POST as $key => $val) {
- // $_POST[$key] = mysql_real_escape_string($_POST[$key]);
- // Or you can use $mysqli->real_escape_string() as above function is deprecated
- // Or you can use prepared statements to sanitize
- // Use stripslashes to do the opposite
- // }
- // do stuffs with validated & safe data
- //show the raw data (for practice)
- // var_dump($_POST);
- // }
- ?> </body> </html>
- this is my textbox and label construct by using opps class concept
- these all values are stored in $par variable
- i want to fetch name value for validation from this array and want to use with $_post[] command
- validate.php
- <?php
- include 'connection.php';
- $error = ""; // Initialize error as blank
- $error1 = "";
- //$username=$_POST['name'];
- //$email=$_POST['email'];
- //$password=$_POST['password'];
- //$password1=$_POST['repassword'];
- if (isset($_POST['submit']))
- { // check if the form is submitted
- #### removing extra white spaces & escaping harmful characters ####
- // $username= trim($_POST['name']);
- $password= trim($_POST['password']);
- $password1= trim($_POST['repassword']);
- $email= trim($_POST['email']);
- if ($username=="") {
- $error1 .= '<p class="error">Username should not be empty</p>';
- }
- // if username is not 3-20 characters long, throw error
- /* if (strlen($username) >= 20) {
- $error .= '<p class="error">Username should be less than 20 character</p>';
- }
- if (ctype_digit($username)) {
- $error1 .= '<p class="error">Username should not accept number</p>';
- }*/
- if (!ctype_alpha($username)) {
- $error .= '<p class="error">Username should accepts only alphabets</p>';
- }
- /* if ($password1 != $password) {
- $error .= '<p class="error"Password not match</p>';
- }*/
- if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) {
- $error .= "Invalid email format";
- }
- else if (isset($_POST['submit']) && $error == '') { // if there is no error, then process further
- //echo "<p class='success'>Form has been submitted successfully.</p>"; // showing success message
- $sql= "insert into reg(name, email, password, repassword,status) Values('". $_POST['name']."', '". $_POST['email']."', '". $_POST['password']."', '". $_POST['repassword']."', '1')";
- $result= mysqli_query($con, $sql);
- if (!$result){
- echo "not connected to database";
- }
- else {
- echo "data entered sucessfully";
- }
- }
- mysqli_close($con);
- }
- ?>