Advertisement
Guest User

Untitled

a guest
Jan 12th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
4CS 4.42 KB | None | 0 0
  1. <html>
  2.    
  3.    <head>
  4.       <title>Bartlomiej Daniel</title>
  5.    </head>
  6.    
  7.    <body>
  8.        <?php
  9.        if (isset($_POST['login'])){
  10.            require 'connect.php';
  11.            $username = $_POST['username'];
  12.            $password = $_POST['password'];
  13.            $result = mysql_query($con, 'SELECT * from account where username="'.$username.'" and password="'.$password.'"');
  14.            if (mysql_num_rows($result)==1){
  15.                $_SESSION['username'] = $username;
  16.                header('Location: welcome.php');
  17.                 }
  18.                 else
  19.                         echo "Accoun't invalid";
  20.         ?>
  21.  
  22.             <form method = "post" action = "home.php?action=login">
  23.                   <table border = "0" cellspacing = "2"
  24.                      cellpadding = "2">
  25.                      <tr>
  26.                         <td>Username</td>
  27.                         <td><input name = "username" type = "text"
  28.                            id = "username"></td>
  29.                         <td>Password</td>
  30.                         <td><input name = "password" type = "text"
  31.                            id = "password"></td>
  32.                            <td>&nbsp;</td>
  33.                            <td><input type="submit" name="login" value="Login"</td>
  34.                      </tr>
  35.                   </table>
  36.              </form>
  37.                      
  38.                      
  39.                <form method = "post" action = "home.php">
  40.                   <table width = "400" border = "0" cellspacing = "1"
  41.                      cellpadding = "2">
  42.                  
  43.                      <tr>
  44.                         <td width = "100">Name</td>
  45.                         <td><input name = "name" type = "text"
  46.                            id = "name"></td>
  47.                      </tr>
  48.                  
  49.                      <tr>
  50.                         <td width = "100">Surname</td>
  51.                         <td><input name = "surname" type = "text"
  52.                            id = "surname"></td>
  53.                      </tr>
  54.                  
  55.                      <tr>
  56.                         <td width = "100">Age</td>
  57.                         <td><input name = "age" type = "int"
  58.                            id = "age"></td>
  59.                      </tr>
  60.                  
  61.                      <tr>
  62.                         <td width = "100">Hometown</td>
  63.                         <td><input name = "hometown" type = "text"
  64.                            id = "hometown"></td>
  65.                      </tr>
  66.  
  67.                      <tr>
  68.                         <td width = "100">Favourite Color</td>
  69.                         <td><input name = "color" type = "text"
  70.                            id = "color"></td>
  71.                      </tr>
  72.  
  73.                       <tr>
  74.                         <td width = "100">Gender</td>
  75.                         <td><input name = "gender" type = "text"
  76.                            id = "gender"></td>
  77.                      </tr>
  78.                  
  79.                      <tr>
  80.                         <td width = "100"> </td>
  81.                         <td>
  82.                            <input name = "add" type = "submit" id = "add"
  83.                               value = "Dodaj">
  84.                         </td>
  85.                      </tr>
  86.                  
  87.                   </table>
  88.                </form>
  89.            
  90. <?php
  91.  
  92.          if(isset($_POST['add']))
  93.             {
  94.             $dbhost = 'localhost';
  95.             $dbuser = 'pz78135';
  96.             $dbpass = 'upiebah1Ie';
  97.             $conn = mysql_connect($dbhost, $dbuser, $dbpass);
  98.  
  99.             if(! $conn)
  100.             {
  101.                 die('Cant connect to database: ' . mysqli_error());
  102.             }
  103.  
  104.             $name = mysql_real_escape_string($_POST['name']);
  105.             $surname = mysql_real_escape_string($_POST['surname']);
  106.             $age = mysql_real_escape_string($_POST['age']);
  107.             $hometown = mysql_real_escape_string($_POST['hometown']);
  108.             $color = mysql_real_escape_string($_POST['color']);
  109.             $gender = mysql_real_escape_string($_POST['gender']);
  110.            
  111.            
  112.             $sql = "INSERT INTO Dane (name, surname, age, hometown, color, gender)
  113.             VALUES('$name', '$surname', '$age', '$hometown', '$color', '$gender')";
  114.            
  115.             mysql_select_db('pz78135');
  116.             $a1 = mysql_query( $sql, $conn );
  117.            
  118.             if(! $a1 )
  119.                 {
  120.                     die('Cant send the data: ' . mysql_error());
  121.                 }
  122.                     echo "1 record was added\n";
  123.             mysql_close($conn);
  124.         } else {
  125. ?>
  126.  
  127.             <?php
  128.          }
  129.       ?>
  130.    
  131.    </body>
  132. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement