diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/edit.inc.php | 21 | ||||
| -rw-r--r-- | test/index.php (renamed from test/test2.php) | 33 | ||||
| -rw-r--r-- | test/test.inc.php | 4 | ||||
| -rw-r--r-- | test/test.php | 34 | 
4 files changed, 42 insertions, 50 deletions
diff --git a/test/edit.inc.php b/test/edit.inc.php index cb0c23f..3309a7b 100644 --- a/test/edit.inc.php +++ b/test/edit.inc.php @@ -1,7 +1,18 @@  <?php -/* -if (isset($_POST['subvar'])) { -  echo $_POST['subvar']; -} -*/  echo $_POST['action']; + +if($_SERVER["REQUEST_METHOD"] == "POST" && isset(_POST['email'])) { +	$email = clear_input($_POST['email']); +	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { +	  echo "Email is not valid: " . $email . "<br>"; +	} else { +	  echo "Email is valid: " . $email . "<br>"; +	} +} + +function clear_input($data) { +  $data = trim($data); +  $data = stripslashes($data); +  $data = htmlspecialchars($data); +  return $data; +} diff --git a/test/test2.php b/test/index.php index 8f2c697..b0cb731 100644 --- a/test/test2.php +++ b/test/index.php @@ -1,3 +1,9 @@ +<?php +if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["name"]) && isset($_POST["date"]) && isset($_POST["time"])) { +  # values will always be set, check if they are empty... +  echo "<strong>You gay!</strong><br>"; +} +?>  <!DOCTYPE html>  <html lang="en">  <head> @@ -12,41 +18,54 @@      padding: 0.2rem;    }  </style> -  <script>  function subAction(action) {    var xhttp = new XMLHttpRequest(); -  /* +    xhttp.onreadystatechange = function() {      if(this.readyState == 4 && this.status == 200) {        console.log(this.responseText);      }    } -  */ +  /*    xhttp.onload = function() {      console.log(this.responseText);    } +  */    xhttp.open("POST", "edit.inc.php", true);    xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    xhttp.send("action=" + action);  }  </script> -  </head>  <body> +<form method="post"> +<label for="name">Name: </label> +<input type="text" name="name" id="name"> +<br> +<label for="date">Date: </label> +<input type="date" name="date" id="date"> +<br> +<label for="time">Time: </label> +<input type="time" name="time" id="time"> +<br> +<input type="submit" value="Submit"> +</form>  <?php  try {    $conn = new PDO("mysql:host=localhost;dbname=testdb", "testuser", "testpass");    echo "<table>\n"; -  echo "<tr><th>Name</th><th>Actions</th></tr>\n"; +  echo "<thead><tr><th>ID</th><th>Name</th><th>Actions</th></tr></thead><tbody>\n";    foreach ($conn->query("SELECT * FROM tbl1") as $row) { -    echo "<tr><td contenteditable=\"true\">" . $row['name'] . "</td>"; +    echo "<tr><td>" . $row['id'] . "</td>"; +    echo "<td contenteditable=\"true\">" . $row['name'] . "</td>";      echo "<td>";      echo "<button onclick=\"subAction('save')\">Save</button>"; +    echo "<button onclick=\"subAction('cancel')\">Cancel</button>";      echo "<button onclick=\"subAction('delete')\">Delete</button>";      echo "</td></tr>\n";    } -  echo "</table>\n"; +  echo "</tbody></table>\n";  }  catch (PDOException $e) {    echo $e->getMessage(); diff --git a/test/test.inc.php b/test/test.inc.php deleted file mode 100644 index 853270c..0000000 --- a/test/test.inc.php +++ /dev/null @@ -1,4 +0,0 @@ -<?php -if (isset($_POST['your-submit'])) { -	# echo $_POST['your-submit']; -} diff --git a/test/test.php b/test/test.php deleted file mode 100644 index 5bca6ac..0000000 --- a/test/test.php +++ /dev/null @@ -1,34 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> -    <meta charset="utf-8"/> -    <meta name="viewport" content="width=device-width initial-scale=1.0"/> -    <link href="../style.css" rel="stylesheet" type="text/css"/> -    <title>Test</title> -</head> -<body> -<main> -<?php -if($_SERVER["REQUEST_METHOD"] == "POST") { -	$email = clear_input($_POST['name']); -	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { -	  echo "You fucking bitch!<br>"; -	} else { -	  echo "You oki: " . $email . "<br>"; -	} -} -function clear_input($data) { -  $data = trim($data); -  $data = stripslashes($data); -  $data = htmlspecialchars($data); -  return $data; -} -include 'test.inc.php'; -?> -<form method="POST"> -<input type="text" name="name"> -<input type="submit" name="your-submit" value="Submit"> -</form> -</main> -</body> -</html>  | 
