-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from SST-CTF/otakar
Added basic PHP
- Loading branch information
Showing
10 changed files
with
540 additions
and
65 deletions.
There are no files selected for viewing
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
(function saveData($) { | ||
var person = prompt('Please enter your name', ''); | ||
$.ajax({ | ||
type: 'POST', | ||
url: './backend.php2', | ||
data: { name: $("select[name='players']").val() }, | ||
success: function (msg) { | ||
alert('Data Saved: ' + msg); | ||
} | ||
}); | ||
}(jQuery)); | ||
|
||
(function sendWPM($) { | ||
var person = prompt('Please enter your name', ''); | ||
$.ajax({ | ||
type: 'POST', | ||
url: './backend.php2', | ||
data: { wpm: $("select[wpm='players']").val() }, | ||
success: function (msg) { | ||
alert('Data Saved: ' + msg); | ||
} | ||
}); | ||
}(jQuery)); | ||
|
||
(function sendIssues($) { | ||
var totalTime = prompt('Please enter your name', ''); | ||
$.ajax({ | ||
type: 'POST', | ||
url: './backend.php2', | ||
data: { issues: $("select[issues='players']").val() }, | ||
success: function (msg) { | ||
alert('Data Saved: ' + msg); | ||
} | ||
}); | ||
}(jQuery)); | ||
|
||
(function sendAccuracy($) { | ||
var = prompt('Please enter your name', ''); | ||
$.ajax({ | ||
type: 'POST', | ||
url: './backend.php2', | ||
data: { accuracy: $("select[accuracy='players']").val() }, | ||
success: function (msg) { | ||
alert('Data Saved: ' + msg); | ||
} | ||
}); | ||
}(jQuery)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
|
||
<html> | ||
|
||
<?php | ||
// define variables and set to empty values | ||
$nameErr = $emailErr = $genderErr = $websiteErr = ""; | ||
$name = $email = $gender = $comment = $website = ""; | ||
|
||
if ($_SERVER["REQUEST_METHOD"] == "POST") { | ||
if (empty($_POST["name"])) { | ||
$nameErr = "Name is required"; | ||
} else { | ||
$name = test_input($_POST["name"]); | ||
// check if name only contains letters and whitespace | ||
if (!preg_match("/^[a-zA-Z ]*$/",$name)) { | ||
$nameErr = "Only letters and white space allowed"; | ||
} | ||
} | ||
} | ||
|
||
function test_input($data) { | ||
$data = trim($data); | ||
$data = stripslashes($data); | ||
$data = htmlspecialchars($data); | ||
return $data; | ||
} | ||
?> | ||
|
||
<body> | ||
<h2>PHP Form Validation Example</h2> | ||
<p><span class="error">* required field.</span></p> | ||
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> | ||
Name: <input type="text" name="name" value="<?php echo $name;?>"> | ||
<span class="error">* <?php echo $nameErr;?></span> | ||
<br><br> | ||
<input type="submit" name="submit" value="Submit"> | ||
</form> | ||
|
||
<?php | ||
//$message = "PHP LOADED"; | ||
//echo "<script type='text/javascript'>alert('$message');</script>"; | ||
|
||
echo "<h2>Your Input:</h2>"; | ||
echo $name; | ||
|
||
$servername = "localhost"; | ||
$username = "www"; | ||
$password = "gfFIw{NHpwCF67"; // TODO: Remove password from index.php by calling password from another file | ||
$dbname = "typing_test"; | ||
|
||
// Create connection | ||
$conn = new mysqli($servername, $username, $password, $dbname); | ||
// Check connection | ||
if ($conn->connect_error) { | ||
die("Connection failed: " . $conn->connect_error); | ||
} | ||
|
||
$sql = "INSERT INTO test (name) | ||
VALUES ('$name')"; | ||
|
||
if ($conn->query($sql) === TRUE) { | ||
echo "New record created successfully"; | ||
} else { | ||
echo "Error: " . $sql . "<br>" . $conn->error; | ||
} | ||
|
||
$conn->close(); | ||
|
||
|
||
?> | ||
</html> |