Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Čia mano html puslapis
- <!DOCTYPE HTML>
- <html>
- <head>
- <title>Home page</title>
- </head>
- <body>
- <form action="studentAdded.php" method="register">
- <h1>Home</h1>
- <h2>Register an user!</h2>
- Username: <input type="text" name="username" size="30" value=""></input><br>
- Password: <input type="text" name="password" size="30" value=""></input><br>
- Email: <input type="text" name="email" size="30" value=""></input><br>
- <input type="submit" name="submit" value="Send" ><br>
- </form>
- <body>
- </html>
- //Čia mano studentAdded.php
- <html>
- <head>
- <title>Home page</title>
- </head>
- <body>
- <?php
- if(isset($_POST['submit'])){
- $data_missing = array();
- if(empty($_POST['username'])){
- // Adds name to array
- $data_missing[] = 'Username';
- } else {
- // Trim white space from the name and store the name
- $UserName = trim($_POST['username']);
- }
- if(empty($_POST['password'])){
- // Adds name to array
- $data_missing[] = 'Password';
- } else{
- // Trim white space from the name and store the name
- $PassWord = trim($_POST['password']);
- }
- if(empty($_POST['email'])){
- // Adds name to array
- $data_missing[] = 'Email';
- } else{
- // Trim white space from the name and store the name
- $Email = trim($_POST['email']);
- }
- if(empty($data_missing)){
- require_once('../../mysqli_connect.php');
- $query = "INSERT INTO users (username, password, email) VALUES (?, ?, ?)";
- $stmt = mysqli_prepare($dbc, $query);
- mysqli_stmt_bind_param($stmt, "sss", $UserName, $PassWord, $Email);
- mysqli_stmt_execute($stmt);
- $affected_rows = mysqli_stmt_affected_rows($stmt);
- if($affected_rows == 1){
- echo 'Student Entered';
- mysqli_stmt_close($stmt);
- mysqli_close($dbc);
- } else {
- echo 'Error Occurred<br />';
- echo mysqli_error();
- mysqli_stmt_close($stmt);
- mysqli_close($dbc);
- }
- } else {
- echo 'You need to enter the following data<br />';
- foreach($data_missing as $missing){
- echo "$missing<br />";
- }
- }
- }
- ?>
- <form action="studentAdded.php" method="register">
- <h1>Home</h1>
- <h2>Register an user!</h2>
- Username: <input type="text" name="username" size="30" value="" ></input><br>
- Password: <input type="text" name="password" size="30" value="" ></input><br>
- Email: <input type="text" name="email" size="30" value="" ></input><br>
- <input type="submit" name="submit" value="Send"><br>
- </form>
- <body>
- </html>
- //Čia mano tas msqli-connect.php
- <?php
- DEFINE ('DB_USER', 'root');
- DEFINE ('DB_PASSWORD', 'elkaso75');
- DEFINE ('DB_HOST', 'localhost');
- DEFINE ('DB_NAME', 'kudzewebsites');
- $dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
- OR die('Could not connect to MySQL: ' .
- mysqli_connect_error());
- ?>
- //O čia mano php failas, per kurį bandau parodyt savo mysql lentelę
- <?php
- // Prijungia prie mysql
- require_once('../../mysqli_connect.php');
- // Sukuria query
- $query = "SELECT username, password, email FROM users";
- // Get a response from the database by sending the connection
- // and the query
- $response = @mysqli_query($dbc, $query);
- // If the query executed properly proceed
- if($response){
- echo '<table align="left"
- cellspacing="5" cellpadding="8">
- <tr><td align="left"><b>Username</b></td>
- <td align="left"><b>Password</b></td>
- <td align="left"><b>Email</b></td></tr>';
- // mysqli_fetch_array will return a row of data from the query
- // until no further data is available
- while($row = mysqli_fetch_array($response)){
- echo '<tr><td align="left">' .
- $row['username'] . '</td><td align="left">' .
- $row['password'] . '</td><td align="left">' .
- $row['email'] . '</td>';
- echo '</tr>';
- }
- echo '</table>';
- } else {
- echo "Couldn't issue database query<br />";
- echo mysqli_error($dbc);
- }
- // Close connection to the database
- mysqli_close($dbc);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement