I have been trying to follow this tutorial from mmtuts:
I can’t get my first part of the tutorial to work but can manage to get the second one. I guess he did say that the second one is better but I am not sure why my first method does work? Here is my code overall so I hope you guys can understand what I am trying to do here… I will put my second code in quotation but it might be incomplete…
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="includes/signup2.php" method="POST">
<?php
if(isset($_GET['firstname'])) {
$first = $_GET['firstname'];
echo '<input type="text" name="firstname" placeholder="firstname" value="'.$first.'">';
}
else {
echo '<input type="text" name="firstname" placeholder="firstname">';
}
if(isset($_GET['lastname'])) {
$last = $_GET['lastname'];
echo ' <input type="text" name="lastname" placeholder="lastname" value="'.$last.'">';
}
else {
echo '<input type="text" name="lastname" placeholder="lastname">';
}
if(isset($_GET['username'])) {
$uid = $_GET['username'];
echo ' <input type="text" name="username" placeholder="username" value="'.$uid.'">';
}
else {
echo '<input type="text" name="username" placeholder="username">';
}
?>
<input type="text" name="email" placeholder="email">
<input type="text" name="password" placeholder="password">
<input type="submit" name="submit" values="register">
</form>
<?php
$fullUrl = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if(strpos($fullURL, "signup=empty") == true) {
echo "You did not fill in all fields!";
exit();
}
elsef(strpos($fullURL, "signup=char") == true) {
echo "You used invalid characters!";
exit();
}
elsef(strpos($fullURL, "signup=email") == true) {
echo "You used an invalid e-mail!!";
exit();
}
elsef(strpos($fullURL, "signup=success") == true) {
echo "You have been signed up!";
}
/*
if(!isset($_GET['signup'])) {
exit();
}
else {
$signupCheck = $_GET['signup'];
if($signupCheck == "empty") {
echo "You did not fill in all fields!";
exit();
}
elseif($signupCheck == "char") {
echo "You used invalid characters!";
exit();
}
elseif($signupCheck == "email") {
echo "You used an invalid e-mail!!";
exit();
}
elseif($signupCheck == "success") {
echo "You have been signed up!";
exit();
}
}
*/
?>
</body>
</html>
This is my other file:
?php
if(isset($_POST['submit'])) {
include_once 'dbh.php';
$username = $_POST['username'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$password = $_POST['password'];
// Throw error messages first and then success messages
if(empty($username) || empty($firstname) || empty($lastname) || empty($email) || empty($password)) {
header('Location: ../index6.php?signup=empty');
exit(); // close off the script....
}
else {
if(!preg_match("/^[a-zA-Z]*$/", $firstname) || !preg_match("/^[a-zA-Z]*$/", $Lastname)) {
header('Location: ../index6.php?signup=char');
exit();
}
else {
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: ../index6.php?signup=email&firstname=$firstname&lastname=$lastname&username=$username");
exit();
}
else {
header('Location: ../index6.php?signup=success');
exit();
}
}
}
}
else {
header('Location: ../index6.php');
}
I get the following errors:
Parse error: syntax error, unexpected ‘echo’ (T_ECHO) in C:\xampp\htdocs\phplessons\index6.php on line 51
I don’t think I did make any mistakes while typing but then again, I might have…